How can I solve this Stata 16 table problem? - Stack Overflow

admin2025-05-02  1

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.

Share Improve this question edited Jan 2 at 16:14 Nick Cox 37.4k6 gold badges35 silver badges50 bronze badges asked Jan 2 at 13:36 Francisco oliveroFrancisco olivero 11 bronze badge 1
  • You posted a version of this at statalist.org/forums/forum/general-stata-discussion/general/… The main point implicit in that thread is that you haven't given us a minimal reproducible example. – Nick Cox Commented Jan 2 at 14:08
Add a comment  | 

1 Answer 1

Reset to default 0

Your problem arises from the fact that Stata 16 and 17 operate slightly differently.

  1. Ensure that you have the "estout" package installed. Type the following into Stata:
ssc install estout
  1. Then change your "esttab" command to "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.

转载请注明原文地址:http://anycun.com/QandA/1746117450a91909.html