Announcement

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

  • Saving mean and CI after "svy: mean" or a more efficient way to plot survey trends with CI's?

    Hello Statalist,

    I'm new to using the -svy- commands and I am trying to construct trend graphs with confidence intervals that take into account the complex survey design. Whereas typically, I would have used twoway (rcap) and twoway (line) and repeat for ~ 4 groups, since I need to account for the survey design, I am using the following instead.

    Code:
    svyset [pweight=poolwt],  strata(varstr) psu(varpsu)  
    
    svy: mean qty, over(year)
    This produces the following output.
    Code:
    --------------------------------------------------------------
                 |             Linearized
            Over |       Mean   Std. Err.     [95% Conf. Interval]
    -------------+------------------------------------------------
    qty          |
            2007 |   139.2986   2.012716      135.3455    143.2517
            2008 |   176.8884   5.057833      166.9546    186.8223
            2009 |   195.9715   5.236264      185.6872    206.2558
            2010 |   217.3776   4.675099      208.1955    226.5597
            2011 |   265.5767   10.75066      244.4619    286.6915
    --------------------------------------------------------------
    when I run this with -return list- I find that the matrix is part of the rclass information. How do I extract the mean and confidence interval so that I can use the twoway (rcap) and twoway (line) to plot the results?

    Alternately, would there be a more efficient way? I am also new to marginsplot but it seems to be a command used after a regression and furthermore, is there a way to specify the confidence intervals and plot multiple lines and confidence intervals within 1 graph like I can with twoway?

    Essentially, I would run the following and save those means and CI's as well, then plot all the different lines on 1 graph

    Code:
    svy: mean qty_2, over(year)
    Thank you in advance.
    I am using Stata SE x64 ver 13.1 with Win 7 x64 and with 8 GB of ram.

  • #2
    You can use Stata's -marginsplot- if you use first use svy:regress to calculate the means. For example:

    Code:
    sysuse auto
    gen sweight=1
    svyset [pw=sweight ]
    svy: reg mpg i.rep78
    margins rep78
    marginsplot
    
    * another option not to connect the individual estimates 
    marginsplot, recast(scatter) name(version2)
    
    * another option to turn the CI into a shaded area with transparency
    marginsplot, recastci(rarea) ciopt(color(%25)) name(version3)

    Comment


    • #3
      Thanks Nicholas, I looked into marginsplot, but I think the issue is that I am trying to plot multiple outcomes in the same graph, for example,

      Code:
      twoway (line qty year) ///
             (line qty_2 year)

      and I don't see a way for marginsplot to do that. So I wonder if there is a way to generate and save the mean and CI from svy: mean to create the graphs myself?
      Last edited by Karl Yesler; 09 Sep 2019, 09:20.
      I am using Stata SE x64 ver 13.1 with Win 7 x64 and with 8 GB of ram.

      Comment


      • #4
        If you have multiple DVs that you want to include on the same graph, my -combomarginsplot- (available from SSC) is probably exactly what you need.

        Comment

        Working...
        X