Some STATA Coding Hint for Estimators

I present here one simple trick that makes your estimation coding much much nicer and faster. I have been using it before, but not with the current laptop. Thus, I just checked how to obtain it.

What does this magical code do?
It creates a nice table of your estimation resultS. This enables you to check many regressions at once. Additionally, the table looks good and it uses the variable names you have in STATA.


First you need the packet. Just type ssc install estout, replace on stata command window. 

Then, when coding, you tell STATA that you want to keep the results by adding eststo: in front of your regression. Here is an example with a loop. 

foreach var in  spill1 spill2 spill3{
eststo: xtgls dlny $explanatory `var', fe
}
esttab using "$caritaoutput\output.rtf", replace

( note that $explanatory gives me variables saved there by global command. It is used like this:
global explanatory var1 var2 var3 var4 )

Without the loop, the estimation would look like this (but report the same thing)
eststo: xtreg dlny $explanatory spill1, fe
eststo: xtreg dlny $explanatory spill2, fe
eststo: xtreg dlny $explanatory spill3, fe


And always remember to add
eststo clear
so that you get rid of the old estimation.


If you have run the estimation before and you have the saved output file open, STATA will give you an error. Luckily, that is easy to fix. Close the file and run esttab --- again.


That's the basics. You can get labels and more statistics with 

esttab using "$caritaoutput\output.rtf", replace ///
 r2  rtf varwidth(22) modelwidth(5) ///
label t(%8.2f) abs  ///
stat(N r2_w r2_b r2_o rho sigma_e sigma_u)

(note that /// changes the line but tells STATA that the following line belongs to the current line)

Comments

Popular posts from this blog

10 Danish Things

Autumn Miracle in Aarhus, Denmark

One More Writing Class - This Time @Aarhus BSS