Skip to content

UndefVarError:r(999)-running reghdfejl in stata #16

@semiloreadegbonmire

Description

@semiloreadegbonmire

Hi David,

I am running a replication package for one of the papers we recently submitted. I have a master.do file that has a master cleaning and analysis file. When I run the whole master.do file, I get the UndefVarError:r(999) when the master analysis file is about to start running as it uses reghdfejl. I'm a bit confused on where this error came from. The weird part is if I run the master do file in a new stata session commenting out the master cleaning file, the master analysis and reghdfejl works fine. I recently started having this issue and I'm looking for how to fix it as ideally I would want the master.do file to be able to run everything. Here's an example:

. ****************************************************************
. *** Main table (IV/RF/OLS)
. ****************************************************************
. if rf_iv_ols'==1 | run_all'==1 {
.
. label var any_inst "Post expansion"
. label var cahoots_any "CRT"
. local ncol = 7
. local tabname "$TABLES/main/table_3.tex"
.
. MultiPartTabStart, ///

ncol(`ncol') tabname(`tabname') ///
caption("Effects of CRT response on call outcomes using expansions as instruments") ///
label("tab:dind_main") scalebox(.8) ///
colnames("CRT" "Police" "Any response" "Arrest" "Invol. hold" "Detox" "Warrant" ) ///
mgroups(`""Call responses" "Call outcomes""') pattern(1 0 0 1 0 0 0) tabular

1 4 8
1,4
4,8

.
.
. // panel A
. MultiPartTabPanelStart, ///

ncol(`ncol') tabname(`tabname') ///
panelstring("Panel A: Reduced form effect of expansion")        

. eststo clear
. foreach y in cahoots_any police_any outcome_any_response outcome_arrest arrest_rept_nch arrest_rept_detox arrest_rept_warrant {
2. eststo: reghdfejl y' any_inst [aw=rewt], absorb(${dind_base_fes}) ${se_dind} 3. qui su y' [aw=rewt] if treat==1 & any_inst==0
4. estadd scalar depmean = r(mean)
5. }
UndefVarError:r(999);
. MultiPartTabPanelEnd, ///

ncol(`ncol') tabname(`tabname') keep(any_inst) ///
stats(depmean, fmt(%9.3f) ///
labels("Untreated mean")) b(%9.3f) substitute(" ." "0." "-." "-0.")

.
. // panel B
. MultiPartTabPanelStart, ///

ncol(`ncol') tabname(`tabname') ///
panelstring("Panel B: IV estimates of effect of CRT response")          

. eststo clear
. eststo: reg police_any
. foreach y in police_any outcome_any_response outcome_arrest arrest_rept_nch arrest_rept_detox arrest_rept_warrant {
2. // hausman test
. ivreghdfe y' (cahoots_any = inst*), absorb(${dind_base_fes}) ${se_dind_iv} endog(cahoots_any) 3. local htest = e(estat) 4. local hpval = e(estatp) 5. . calc_ccm y', d(cahoots_any) z(inst*) absorb(${dind_base_fes}) ${se_dind}
6. local ccm = r(ccm)
7. eststo: ivreghdfe y' (cahoots_any = inst*), absorb(${dind_base_fes}) ${se_dind} 8. estadd scalar ccm = ccm'
9. estadd scalar fstat = e(widstat)
10. estadd local newline_lab ""
11. estadd scalar jtest = e(j)
12. estadd scalar jpval = e(jp)
13. estadd scalar htest = htest' 14. estadd scalar hpval = hpval'
15. }
. MultiPartTabPanelEnd, ///

ncol(`ncol') tabname(`tabname') keep(cahoots_any) ///
stats(ccm fstat newline_lab jtest jpval newline_lab htest hpval, ///
      fmt(%9.3f %9.2f %9.2f %9.3f %9.3f %9.3f %9.3f %9.3f) ///
      labels("Control complier mean" "First-stage F-stat" ///
      "\(J\) test of overidentification" "\quad \(\chi^2\) statistic" "\quad \(p\)-value" ///
      "Hausman test" "\quad \(\chi^2\) statistic" "\quad \(p\)-value" )) ///
b(%9.3f) substitute(" ." "0." "-." "-0.")

.
. // panel C
. MultiPartTabPanelStart, ///

ncol(`ncol') tabname(`tabname') ///
panelstring("Panel C: OLS estimates of effect of CRT response")        

. eststo clear
. eststo: reg police_any
. foreach y in police_any outcome_any_response outcome_arrest arrest_rept_nch arrest_rept_detox arrest_rept_warrant {
2. eststo: reghdfejl y' cahoots_any, absorb(${dind_base_fes}) ${se_dind} 3. su y' if cahoots_any==0
4. estadd scalar depmean = r(mean)
5. estadd scalar obs_full = e(N_full)
6.
. }
. MultiPartTabPanelEnd, ///

ncol(`ncol') tabname(`tabname') keep(cahoots_any) ///
stats(depmean obs_full, fmt(%9.3f %9.0fc) ///
labels("Untreated mean" "Observations")) ///
b(%9.3f) substitute(" ." "0." "-." "-0.")

. MultiPartTabEnd, ///

ncol(`ncol') tabname(`tabname') scalebox width(1) notes(" ") tabular

. }
r(999);
r(999);
r(999);

end of do-file

r(999);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions