Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • STATA loop problem

    Hello everyone,

    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

    Also, when the table is exported to latex the line "\beta_2+\beta_3=0" is exported as "\beta\_2+\beta\_3=0". I want to know how to delete that second backlash.

    Thanks!

  • #2
    There is not much to go on regarding your first question. Instead of defining a global macro 'outcomes,' which is not shown here, use a local macro and explicitly define it within the do-file. It is possible that the global macro is defined differently than you expect. For your question about underscores and esttab while exporting to LaTeX, see https://www.statalist.org/forums/for...n-extra-to-tex. Note that estout is from SSC (FAQ Advice #12).

    Comment

    Working...
    X