Announcement

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

  • Svy & gen or egen

    Hi!
    Is there any way to use the svy command and generate a new variable at the same time?
    As do this svy: mean var, over(area)
    but generate a new variable with the results?
    area var area_mean (new var)
    rural 1 mean for rural
    urban 1 mean for urban
    urban 0 mean for urban
    rural 0 mean for rural
    urban 0 mean for urban
    rural 1 mean for rural
    rural 1 mean for rural
    rural 1 mean for rural
    Best,
    Alex

  • #2
    -generate- and -egen- are not designed to be used as estimation commands, which is essentially how you are wanting to use them. Here's an example using the NHANES data example from the -svy- manual.

    Code:
    clear *
    cls
    
    webuse nhanes2f
    svyset psuid [pweight=finalwgt], strata(stratid)
    svy: mean zinc, over(female)
    svy, coeflegend
    
    gen double means = cond(female==0, _b[[email protected]], _b[[email protected]])

    Comment

    Working...
    X