Announcement

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

  • Help exporting svy: two-way tabulate to excel.

    Hello,

    I am trying to export some results to excel of a svy: two-way tabulate but I'm running into trouble when trying to store it as a matrix in order to export. The results are running in the stata console but then exporting blank. I'd like the column results stored, as well as the labels of the variables. If anyone has any insights that would be great. Thank you!

    clear
    use "$cleandata/final_analysis.dta"
    putexcel set "$output/figures.xlsx", sheet("Figure 3") modify
    putexcel A1 = "Figure 3. Training"
    putexcel A2 = ("Training") B2 = ("Contract") C2 = ("Government")

    svyset school_code [pw=teacher_weight_component], singleunit(certainty) strata(strata)
    svy: tabulate training government, column cell

    matrix results = r(cell)

    local lblname : value label training
    levelsof training, local(levels)

    local labels foreach level of local levels {
    local label : label `lblname' `level'
    local labels `labels' `"`label'"'
    }

    local row = 3
    foreach label of local labels {
    putexcel A`row' = "`label'"
    local row = `row' + 1
    }

    putexcel B3=matrix(results)
Working...
X