Announcement

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

  • Resetting a CSV file in an esttab loop

    Hi everyone!
    I run the following loop:
    Code:
    global Vars var1 var2 var3
    foreach v in $Vars{
    reg y x if `v'
    reg y x z if `v'
    
    esttab using "results.csv", se label append
    }
    This loop runs over three subsamples defined by the variables var1, var2, and var3. Within each subsample, it performs:
    1. Estimation of two regressions
    2. Appending these estimates to the file "results.csv"
    I would like to run a little more sophisticated loop that resets or replaces "results.csv" before exporting the estimates.


    I'd appreciate your help!

  • #2
    estout is from SSC, as you are asked to explain in FAQ Advice #12. You can set a condition that depends on the iteration of the loop, for example,

    Code:
    local i 1
    foreach v in var1 var2 var3{
        reg y x if `v'
        reg y x z if `v'
        local opt= cond(`i'==1, "replace", "append")
        esttab using "results.csv", se label `opt'
        local ++i
    }

    Comment

    Working...
    X