1
votes

So I am running an 2SLS model by interview year and I have many interview years and different models. I want to present the first-stage results first and then after reassuring the reader that they are solid move on to the interesting results.

Example of Table A (first stage):

Year DV Coef SE F N

1 A 0.5 0.1 100 1000

2 A 0.8 0.2 10 1500

3 B -0.6 0.4 800 800

Table B with the main results would look the same just without the F-Stat.

I searched on the web about how to create those tables automatically in Stata, but despite finding many questions I didn't find an answer that worked for me. From those different posts and help-files I build something that is nearly there.

It creates the table I want for the main results with the F-Stat together by some variable (Step A in the code). However, when I move on to do the same for the first stage it only saves the last wave as I restore the estimates. I understand why Stata does it like that, but I cannot think of a way of convincing it to do what I want.

clear all

*Install user-written commands
ssc install outreg2, replace
ssc install ivreg210, replace

*load data
sysuse auto, clear

*run example model (obviously the model itself is bogus)
********************************************************
*Step A: creates the IV results by foreign plus the F-Statistic
bys foreign:  ///
    outreg2 using output1-IV-F, label excel stats(coef se) dec(2) adds(F-Test, e(widstat)) nocons nor2 keep(mpg) replace: ///
    ivreg210 price headroom trunk (mpg=rep78 ), savefirst first
*Step B: creates the first stage results in a seperate table
bys foreign:  ///
    ivreg210 price headroom trunk (mpg=rep78 ), savefirst first
    est restore _ivreg210_mpg   
    outreg2 using output1_1st-stage, replace keep(rep78)

cap erase output1-IV-F
cap erase output1_1st-stage

So ideally I would only run the model once and have the F-Stat in the first-stage table, but I can fix that manually. The biggest issue I have is how to store the estimates when using bysort. If anyone has any suggestions about that, I would greatly appreciate it.

Thanks!

2

2 Answers

0
votes
ssc install estout

then you can store whatever result you want for later use, even after a bysort.

eststo clear
sysuse auto, clear
bysort foreign: eststo: reg price weight mpg
esttab, label nodepvar nonumber
-1
votes

This is a round-about solution. It works, but really isn't the proper solution I was/am looking for. The "trick" is to run the 1st stage as a separate model.

clear all

*Install user-written commands
ssc install outreg2, replace
ssc install ivreg210, replace

*load data
sysuse auto, clear

*run example model (obviously the model itself is bogus)
********************************************************
*Step A: creates the IV results by foreign plus the F-Statistic
bys foreign:  ///
    outreg2 using output1-IV-F, label excel stats(coef se) dec(2) adds(F-Test, e(widstat)) nocons nor2 keep(mpg) replace: ///
    ivreg210 price headroom trunk (mpg=rep78 ), savefirst first

*Step B: creates the first stage results in a seperate table
bys foreign:  ///
    ivreg210 price headroom trunk (mpg=rep78 ), savefirst first
    est restore _ivreg210_mpg   
    outreg2 using output1_1st-stage1, replace keep(rep78)

*************   
/* NEW BIT */   
*************   
*Step C: creates the first stage results in a seperate table
bys foreign:  ///
    outreg2 using output1_1st_NEW, label excel stats(coef se) dec(2) nocons nor2 keep(rep78) replace: ///
    reg mpg headroom trunk rep78

cap erase output1-IV-F
cap erase output1_1st-stage1
cap erase output1_1st_NEW