I created this code that works correctly in Stata 17, but when I try to replicate and run it in Stata 16, it produces errors. The main issue is that it only generates the table considering the first local variable created. I would like to understand why this happens.
local sample_openx "Full"
local sample_first_offer_x_gets "Decider Opens"
// Electronic vs Face-to-Face regression
foreach var of varlist $outcomes {
eststo `var': reg `var' Forced##face i.round_dummy ///
if $sample_reg, vce(cluster Participant_id)
qui test 1.face+1.Forced#1.face==0
local combined = `r(p)'
local combined: display %9.4f `combined'
qui estadd local combined "`combined'"
qui sum `var' if e(sample)==1
qui estadd scalar meanc r(mean)
local sample_text "`sample_`var''"
qui estadd local Sample "`sample_text'"
}
esttab $outcomes ///
using "$latex/table_reg_face.tex", replace ///
keep (1.Forced 1.face 1.Forced#1.face) ///
b(2) se(2) star(* 0.10 ** 0.05 *** .01) ///
mtitles("Decider Opens" "Decider's First Claim") collabels(none) ///
varlabels(1.Forced "Forced" 1.face "Face-to-Face" 1.Forced#1.face "Forced $*$ Face-to-Face") ///
noobs nocons booktabs nonotes ///
stats(N N_clust meanc combined Sample, fmt(%9.0fc 0 2 0) labels("Observations" "Num. Clusters" "Dep. Var. Mean" "\beta_2+\beta_3=0" "Sample"))
eststo clear
I have tried to modify the order of the local variables and I realized that the code is only exporting the data from the first variable.
I created this code that works correctly in Stata 17, but when I try to replicate and run it in Stata 16, it produces errors. The main issue is that it only generates the table considering the first local variable created. I would like to understand why this happens.
local sample_openx "Full"
local sample_first_offer_x_gets "Decider Opens"
// Electronic vs Face-to-Face regression
foreach var of varlist $outcomes {
eststo `var': reg `var' Forced##face i.round_dummy ///
if $sample_reg, vce(cluster Participant_id)
qui test 1.face+1.Forced#1.face==0
local combined = `r(p)'
local combined: display %9.4f `combined'
qui estadd local combined "`combined'"
qui sum `var' if e(sample)==1
qui estadd scalar meanc r(mean)
local sample_text "`sample_`var''"
qui estadd local Sample "`sample_text'"
}
esttab $outcomes ///
using "$latex/table_reg_face.tex", replace ///
keep (1.Forced 1.face 1.Forced#1.face) ///
b(2) se(2) star(* 0.10 ** 0.05 *** .01) ///
mtitles("Decider Opens" "Decider's First Claim") collabels(none) ///
varlabels(1.Forced "Forced" 1.face "Face-to-Face" 1.Forced#1.face "Forced $*$ Face-to-Face") ///
noobs nocons booktabs nonotes ///
stats(N N_clust meanc combined Sample, fmt(%9.0fc 0 2 0) labels("Observations" "Num. Clusters" "Dep. Var. Mean" "\beta_2+\beta_3=0" "Sample"))
eststo clear
I have tried to modify the order of the local variables and I realized that the code is only exporting the data from the first variable.
Your problem arises from the fact that Stata 16 and 17 operate slightly differently.
ssc install estout
estout $outcomes using "$latex/table_reg_face.tex", replace ///
cells(b(fmt(2)) se(fmt(2))) ///
keep(1.Forced 1.face 1.Forced#1.face) ///
varlabels(1.Forced "Forced" 1.face "Face-to-Face" 1.Forced#1.face "Forced * Face-to-Face") ///
stats(N N_clust meanc combined Sample, fmt(%9.0fc 0 2 0) labels("Observations" "Num. Clusters" "Dep. Var. Mean" "β₂+β₃=0" "Sample")) ///
starlevels(* 0.10 ** 0.05 *** 0.01) ///
title(Decider Opens and Decider's First Claim) ///
style(tex) ///
prehead("\begin{table}[htbp]\centering" "\caption{@title}" "\begin{tabular}{lcc}") ///
postfoot("\end{tabular}" "\end{table}")
This should work in Stata 16 and create a table similar to the one you want.
You must not forget to clear your saved estimates after:
eststo clear
If you are still experiencing issues, you can try executing your code step by step to identify where it stops working.