Announcement

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

  • How to loop through two locals instead of all variables inside each local


    Code:
      local ipv "angry fear intimacy_idx cont12_idx ev12_idx pv12_idx sv12_idx ipv_ovall_idx" local ipv_12_entire "cont12_idx ev12_idx pv12_idx sv12_idx cont_idx ev_idx pv_idx sv_idx"   *------------------------------------------------------------------------------* * REGRESSION TABLES: PANEL A *------------------------------------------------------------------------------*  * IPV outcomes  eststo clear  foreach outcome of local ipv {      eststo `outcome'_demo: reg `outcome' arm_free `demo_controls', vce(cluster new_csps)         estadd local demo_ctrl "Yes" : `outcome'_demo               estadd local fe "None" : `outcome'* }     estout * using "${Oleaf}/REG_IPV/panelA_ipv.tex", replace           * Violence indexes (12 months VS entire marriage) eststo clear  foreach outcome of local ipv_12_entire {      eststo `outcome'_demo: reg `outcome' arm_free `demo_controls', vce(cluster new_csps)         estadd local demo_ctrl "Yes" : `outcome'_demo               estadd local fe "None" : `outcome'* }     estout * using "${Oleaf}/REG_IPV/panelA_ipv_12_entire.tex", replace
    If I do the above by running two separate regressions, it works as intended. However, I would like to run the two locals "ipv" and "ipv_12_entire" inside a loop. I did the following. And instead of looping over two locals as I'd like, the code below is looping every variable inside each local. Is there a way to write a loop with grouping locals?

    Code:
     loc i = 1   eststo clear foreach outcome of local `ipv' `ipv_12_entire' {          eststo `outcome': reg `outcome' arm_free `demo_controls', vce(cluster new_csps)         estadd local demo_ctrl "Yes" : `outcome'         estadd local fe "None" : `outcome'      estout * using "${Oleaf}/REG_IPV/panelA_`outcome'.tex", replace  loc i = `i' + 1     }

  • #2
    Restructure your code please.

    Comment


    • #3
      Reposted, with subsequent response, at

      https://www.statalist.org/forums/for...ide-each-local

      Comment

      Working...
      X