Announcement

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

  • saving and exporting svy results using -over- across two variables

    Hi all,

    Thanks for creating a space to help people understand STATA! I’m predominantly an R user, but have been able to use STATA thanks in large part to this community.

    I’m working with survey data in STATA, and have several estimates for distinct questions I’d like to save separately in .csv or excel files. I would like to save the estimates themselves, along with the std errors to produce confidence intervals.

    The trick seems to be that I need to cut the data across two variables, one delineating rural (a simple binary variable) and the other race (a categorical variable that runs from 1, 2, 3). So the structure of the estimate production will look like this: “svy: prop question, over (rural race)”.

    I have seen multiple tries at this on this website where the estimates are estimated -over- just one variable, but I have struggled to find where it Is estimated using more than one. As a reminder, I really need the estimate and se for race and rurality. Given that I’m only using three variables for race and two for rural, that means six total mean and se estimates.

    I’m open to saving results into a matrix, or using -putexcel-, or really anything that allows me to save and export the estimates across the two variables.

    Below is what my code would look like now

    HTML Code:
    svyset [pw = weight_cumulative]
    
    svy: prop enviro_carbon_reg, over (rural race)
    

  • #2
    svy: prop saves results in r(table), so you can extract this matrix and export. Below, I use estout from SSC.

    Code:
    svyset [pw = weight_cumulative]
    svy: prop enviro_carbon_reg, over (rural race)
    mat toexport= r(table)[1..6, 1...]'
    esttab mat(toexport) using myfile.csv, replace nomtitle

    Comment

    Working...
    X