Announcement

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

  • How to transfer means and standard errors from a log file into an Excel file?

    Dear Statalisters,

    I am trying to find a way to transfer only the mean and standard error (not the entire content) from a log file into an Excel file. I tried the putexcel function but I do not find a way for this to work when my codes include locals and a foreach command. For example:
    Code:
    local personal "age agesq male ethnic_minority mnact_working eduyears_completed marit_married  relig_* borncntry i.hincome urbanicity_city urbanicity_suburb i.year"
    local instrument "prosec_judge_exam_exper_index"
    local country "clearrate_crim_avg gdp avg_schooling15"
    local lawvar "judicial_pca3"
    local dishonesty "document2 claimbenef2 bribe2 scndhand2"
    
    foreach x in `dishonesty' {
    quietly reg `x' `lawvar' `country' `personal' own_home rooms_house [pweight=dweight], vce(cluster Agecountry)
    sum `x' [aweight=dweight] if e(sample)
    }
    Does anyone know how to do this? Since I've got hundreds of tables within log files that include means and standard errors I'm interested in, it would save me lots of time (at the moment I'm just copy-pasting everything).

    Thanks in advance.

    Kind regards,

    Eline

  • #2
    Code:
    local personal "age agesq male ethnic_minority mnact_working eduyears_completed marit_married  relig_* borncntry i.hincome urbanicity_city urbanicity_suburb i.year"
    local instrument "prosec_judge_exam_exper_index"
    local country "clearrate_crim_avg gdp avg_schooling15"
    local lawvar "judicial_pca3"
    local dishonesty "document2 claimbenef2 bribe2 scndhand2"
    local n: word count `dishonesty'
    matrix R = J(`n',2,.)
    
    local i=1
    foreach x in `dishonesty'{
    quietly reg `x' `lawvar' `country' `personal' own_home rooms_house [pweight=dweight], vce(cluster Agecountry)
    sum `x' [aweight=dweight] if e(sample)
    matrix R[`i',1] =r(mean)
    matrix R[`i',2] =r(sd)
    local ++i
    }
    
    putexcel set "results.xls", sheet("Mean and SD results") 
    putexcel A1=("Mean")
    putexcel B1=("SD")
    putexcel A2=matrix(R)

    Comment

    Working...
    X