Announcement

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

  • Output Results from a RANGE of Variables to Single Excel/.csv file

    RE: Output Results from a RANGE of Variables to Single Excel/.csv file

    Hi, I'm running tab queries (foreach loop) on a series of health condition variables and was wondering if I can output/export them somehow into a single .csv results table?

    Here's my loop code -


    foreach n of varlist b_hcondn1 b_hcondn2 b_hcondn3 b_hcondn4 b_hcondn5 ///
    b_hcondn6 b_hcondn7 b_hcondn8 b_hcondn9 b_hcondn10 b_hcondn11 ///
    b_hcondn12 b_hcondn13 b_hcondn14 b_hcondn15 b_hcondn16 b_hcondn17{

    tab `n' if `n' >=0

    }

    Thanks in advance.

    SCE
    Last edited by Sue Sheffield; 03 Feb 2022, 06:49.

  • #2
    First:

    Code:
    ssc install estout, replace
    Then you can do something like:

    Code:
    eststo clear
    forval i=1/17{
        eststo m`i': estpost tab b_hcondn`i' if b_hcondn`i' >=0
        local opt = cond(`i'==1, "replace", "append")
        esttab m`i' using myfile.csv, cells("b pct cumpct") `opt' nonumb
    }

    Comment


    • #3
      Thanks Andrew I'll try that!

      Sue

      Comment

      Working...
      X