Announcement

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

  • Estout and svy

    Hello, I am trying to create some descriptive tables using estout and esttab (SSC). I am also using svy. My data is on a restricted server, and I'm not familiar with any default Stata datasets that contain survey weights, so I regretfully do not have any example data to show, but hopefully my predicament is straightforward.

    I have a few variables that are dichotomous (for example, white, black, gender, etc.) and a few that are continuous (test score, age, etc.). My goal is to simply pull out their proportions/means and standard deviations.

    For the dichotomous variables, the syntax seems simple enough:

    Code:
    estpost svy: tab black
    eststo
    estpost svy: tab gender
    eststo
    esttab using "example.csv", cell("b se")

    However, for the continuous variables, estpost does not seem to be compatible with svy: mean.

    Code:
    estpost svy: mean age
    This throws an error "invalid command".

    Does anyone have any ideas for a workaround or other solution for storing values of these continuous variables alongside the dichotomous ones?

  • #2
    estout is from SSC, as you are asked to explain (FAQ Advice #12). mean is an estimation command and thus it saves its results in e(), so you do not need to post them. You can create a data example from one of Stata's datasets, note that the issue of confidential data is already dealt with in the referenced FAQ Advice.

    Comment


    • #3
      Edited: post #2 from Andrew Musau pointed the way. What follows replaces the original of this post.

      To find a default dataset containing survey weights, you need look no further than the output of
      Code:
      help svy
      to find examples using one such dataset. Using that dataset, the following accomplishes what I understand you to seek,
      Code:
      clear all
      webuse nhanes2f
      svyset psuid [pweight=finalwgt], strata(stratid)
      
      // duplicate esttab example
      estpost svy: tab sex
      eststo
      estpost svy: tab race
      eststo
      
      svy: mean age
      eststo
      esttab, cell("b se")
      Code:
      . esttab, cell("b se")
      
      ------------------------------------------------------------------------------------------
                            (1)                       (2)                       (3)            
                           Mean                      Mean                      Mean            
                              b           se            b           se            b           se
      ------------------------------------------------------------------------------------------
      Male             .4795785      .005773                                                    
      Female           .5204215      .005773                                                    
      Total                   1            0            1            0                          
      White                                      .8790162     .0167217                          
      Black                                      .0956152     .0127777                          
      Other                                      .0253686     .0105544                          
      age                                                                  42.23732     .3034412
      ------------------------------------------------------------------------------------------
      N                   10337                     10337                     10337            
      ------------------------------------------------------------------------------------------
      Last edited by William Lisowski; 23 Jul 2022, 13:15.

      Comment


      • #4
        Thank you much, William Lisowski. I'm hopeful there's perhaps a different community contributed package or other clever workaround that I'm not familiar with.

        Comment


        • #5
          Please revisit post #3, which was heavily edited in light of post #2 as you were posting #4. In my defense, I'm not a regular user of esttab and didn't understand that there was no real magic to estpost.

          Comment


          • #6
            Ah I see now, this makes a lot of sense--and that makes two of us (re: not being a regular user of esttab). Thanks to both of you.

            Comment


            • #7
              Andrew Musau, a follow-up question that you might have knowledge of: is it possible to have eststo and esttab produce standard deviations instead of standard errors? Using the example data that William Lisowski pointed me towards, I can use a svy: postestimation command (estat sd) to produce the standard deviation but cannot figure out how to incorporate that into eststo and esttab. The below code leaves -sd- blank, as it seems like eststo ignores -estat sd-.

              EDIT: code was showing up strangely
              Code:
              clear all
              webuse nhanes2f
              svyset psuid [pweight=finalwgt], strata(stratid)
              
              
              svy: mean sex
              estat sd
              eststo
              esttab, cell("b se sd")
              Last edited by Dakota McAvoy; 23 Jul 2022, 14:12.

              Comment


              • #8
                Code:
                clear all
                webuse nhanes2f
                svyset psuid [pweight=finalwgt], strata(stratid)
                svy: mean sex 
                estat sd
                estadd mat sd= r(sd)
                esttab, cell("b se sd")
                Res.:

                Code:
                . svy: mean sex 
                (running mean on estimation sample)
                
                Survey: Mean estimation
                
                Number of strata =      31      Number of obs   =       10,337
                Number of PSUs   =      62      Population size =  117,023,659
                                                Design df       =           31
                
                --------------------------------------------------------------
                             |             Linearized
                             |       Mean   Std. Err.     [95% Conf. Interval]
                -------------+------------------------------------------------
                         sex |   1.520421    .005773      1.508647    1.532196
                --------------------------------------------------------------
                
                . 
                . estat sd
                
                -------------------------------------
                             |       Mean   Std. Dev.
                -------------+-----------------------
                         sex |   1.520421     .499607
                -------------------------------------
                
                . 
                . estadd mat sd= r(sd)
                
                added matrix:
                                 e(sd) :  1 x 1
                
                . 
                . esttab, cell("b se sd")
                
                ---------------------------------------------------
                                      (1)                          
                                     Mean                          
                                        b           se           sd
                ---------------------------------------------------
                sex              1.520421      .005773      .499607
                ---------------------------------------------------
                N                   10337                          
                ---------------------------------------------------

                Comment

                Working...
                X