Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re:st: margins, vce(unconditional) after estimation with replicate weights


From   Steve Samuels <[email protected]>
To   [email protected]
Subject   Re:st: margins, vce(unconditional) after estimation with replicate weights
Date   Tue, 6 Nov 2012 14:01:37 -0500

Sam Schulhofer-Wohl <[email protected]> wrote on Nov. 5:

     I get a syntax error message, r(459), when I try to use -margins,
     vce(unconditional)- after estimating a linear regression in survey data
     with SDR or BRR weights.

The manual entry for -margins- (p. 1077, Version 12) states that
vce(unconditional) uses the linearized variance matrix, so, by
implication, can't be used directly with replicate-based standard
errors.  I forwarded Sam's post to Stata Technical support. Isabelle
Canette of StataCorp, responded and demonstrated how to write a wrapper
program to feed into -svy: brr-, -svy: sdr-, or -svy: jackknife-.


Steve


The option -vce(unconditional)- for -margins- uses the linearized
variance estimator to compute the standard errors. Therefore, it can't
be used with -svy brr-.
If you want to compute standard errors for your margins based on
balanced repeated replications, you can write a wrapper for your
command and for -margins- and call it with -svy brr-, for example:

 use nhanes2brr, clear

 capture program drop mymargins

 program mymargins, eclass
   version 12
   syntax [anything] [if] [iw pw]
   if "`weight'" != "" {
     local wgtexp "[`weight' `exp']"
   }
   set buildfvinfo on
   logit highbp  weight i.region `if' `wgtexp'
   margins region, post
 end

 webuse nhanes2brr, clear
 svy brr _b: mymargins


Notice that the program (-mymargins-) needs to accept weights.
Also, the line
 set buildfvinfo on
is set so -margins- checks for estimability. It is usually set
on, but when using replication methods is set off because it
increases the computation time, so you need to set it on.
The option -post- for -margins- posts the results on e(b), so
they can be used by -svy brr-.



-----Begin Original Message-----
Re: 	st: margins, vce(unconditional) after estimation with replicate weights
From:  	Sam Schulhofer-Wohl <[email protected]>


I get a syntax error message, r(459), when I try to use -margins,
vce(unconditional)- after estimating a linear regression in survey
data with SDR or BSR weights. There is no error when I don't specify
vce(unconditional) or when I don't use replicate weights. Some
examples are below.

I think this may be the same problem that Eva Chang mentioned at
http://www.stata.com/statalist/archive/2012-09/msg01007.html, but I
don't see any replies to Eva's message.

I also can't find any indication in the manual that -margins,
vce(unconditional)- is incompatible with replicate weights.

Any suggestions on how to avoid this error?

--
Sam Schulhofer-Wohl
Senior Economist
Research Department
Federal Reserve Bank of Minneapolis
90 Hennepin Ave.
Minneapolis MN 55480-0291
[email protected]


*example of the error using SDR weights

. webuse ss07ptx

. svyset

    pweight: pwgtp
        VCE: sdr
        MSE: off
  sdrweight: pwgtp1 pwgtp2 pwgtp3 pwgtp4 pwgtp5 pwgtp6 pwgtp7 pwgtp8
pwgtp9 pwgtp10 pwgtp11 pwgtp12 pwgtp13 pwgtp14 pwgtp15 pwgtp16 pwgtp17
pwgtp18 pwgtp19
             pwgtp20 pwgtp21 pwgtp22 pwgtp23 pwgtp24 pwgtp25 pwgtp26
pwgtp27 pwgtp28 pwgtp29 pwgtp30 pwgtp31 pwgtp32 pwgtp33 pwgtp34
pwgtp35 pwgtp36 pwgtp37
             pwgtp38 pwgtp39 pwgtp40 pwgtp41 pwgtp42 pwgtp43 pwgtp44
pwgtp45 pwgtp46 pwgtp47 pwgtp48 pwgtp49 pwgtp50 pwgtp51 pwgtp52
pwgtp53 pwgtp54 pwgtp55
             pwgtp56 pwgtp57 pwgtp58 pwgtp59 pwgtp60 pwgtp61 pwgtp62
pwgtp63 pwgtp64 pwgtp65 pwgtp66 pwgtp67 pwgtp68 pwgtp69 pwgtp70
pwgtp71 pwgtp72 pwgtp73
             pwgtp74 pwgtp75 pwgtp76 pwgtp77 pwgtp78 pwgtp79 pwgtp80
Single unit: missing
   Strata 1: <one>
       SU 1: <observations>
      FPC 1: <zero>

. svy: reg agep i.sex
(running regress on estimation sample)

SDR replications (80)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
..............................

Survey: Linear regression                       Number of obs      =    230817
                                              Population size    =  23904380
                                              Replications       =        80
                                              Wald chi2(1)       =   1515.50
                                              Prob > chi2        =    0.0000
                                              R-squared          =    0.0021

------------------------------------------------------------------------------
           |                 SDR
      agep |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     2.sex |   1.994219   .0512265    38.93   0.000     1.893817    2.094621
     _cons |   33.24486   .0470986   705.86   0.000     33.15255    33.33717
------------------------------------------------------------------------------

. margins sex, vce(unconditional)
vce(sdr) is not supported
something that should be true of your data is not
r(459);

*margins works fine if I don't specify vce(unconditional)

. margins sex

Adjusted predictions                              Number of obs   =     230817
Model VCE    : SDR

Expression   : Linear prediction, predict()

------------------------------------------------------------------------------
           |            Delta-method
           |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       sex |
        1  |   33.24486   .0470986   705.86   0.000     33.15255    33.33717
        2  |   35.23908   .0386398   911.99   0.000     35.16335    35.31481
------------------------------------------------------------------------------

*using the BSR equivalent of SDR doesn't help

. svyset [pw=pwgtp], bsrweight(pwgtp?*) bsn(4) vce(bootstrap)

    pweight: pwgtp
        VCE: bootstrap
        MSE: off
  bsrweight: pwgtp1 pwgtp2 pwgtp3 pwgtp4 pwgtp5 pwgtp6 pwgtp7 pwgtp8
pwgtp9 pwgtp10 pwgtp11 pwgtp12 pwgtp13 pwgtp14 pwgtp15 pwgtp16 pwgtp17
pwgtp18 pwgtp19
             pwgtp20 pwgtp21 pwgtp22 pwgtp23 pwgtp24 pwgtp25 pwgtp26
pwgtp27 pwgtp28 pwgtp29 pwgtp30 pwgtp31 pwgtp32 pwgtp33 pwgtp34
pwgtp35 pwgtp36 pwgtp37
             pwgtp38 pwgtp39 pwgtp40 pwgtp41 pwgtp42 pwgtp43 pwgtp44
pwgtp45 pwgtp46 pwgtp47 pwgtp48 pwgtp49 pwgtp50 pwgtp51 pwgtp52
pwgtp53 pwgtp54 pwgtp55
             pwgtp56 pwgtp57 pwgtp58 pwgtp59 pwgtp60 pwgtp61 pwgtp62
pwgtp63 pwgtp64 pwgtp65 pwgtp66 pwgtp67 pwgtp68 pwgtp69 pwgtp70
pwgtp71 pwgtp72 pwgtp73
             pwgtp74 pwgtp75 pwgtp76 pwgtp77 pwgtp78 pwgtp79 pwgtp80
        bsn: 4
Single unit: missing
   Strata 1: <one>
       SU 1: <observations>
      FPC 1: <zero>

. svy: reg agep i.sex
(running regress on estimation sample)

Bootstrap replications (80)
----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
..................................................    50
..............................

Survey: Linear regression                       Number of obs      =    230817
                                              Population size    =  23904380
                                              Replications       =        80
                                              Wald chi2(1)       =   1515.50
                                              Prob > chi2        =    0.0000
                                              R-squared          =    0.0021

------------------------------------------------------------------------------
           |   Observed   Bootstrap                         Normal-based
      agep |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     2.sex |   1.994219   .0512265    38.93   0.000     1.893817    2.094621
     _cons |   33.24486   .0470986   705.86   0.000     33.15255    33.33717
------------------------------------------------------------------------------

. margins sex, vce(unconditional)
vce(bootstrap) is not supported
something that should be true of your data is not
r(459);

*no problem if I don't use replicate weights

. svyset [pw=pwgtp]

    pweight: pwgtp
        VCE: linearized
Single unit: missing
   Strata 1: <one>
       SU 1: <observations>
      FPC 1: <zero>

. svy: reg agep i.sex
(running regress on estimation sample)

Survey: Linear regression

Number of strata   =         1                  Number of obs      =    230817
Number of PSUs     =    230817                  Population size    =  23904380
                                              Design df          =    230816
                                              F(   1, 230816)    =    350.93
                                              Prob > F           =    0.0000
                                              R-squared          =    0.0021

------------------------------------------------------------------------------
           |             Linearized
      agep |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
     2.sex |   1.994219   .1064544    18.73   0.000     1.785571    2.202867
     _cons |   33.24486   .0730543   455.07   0.000     33.10168    33.38805
------------------------------------------------------------------------------

. margins sex, vce(unconditional)

Adjusted predictions                            Number of obs      =    230817

Expression   : Linear prediction, predict()

------------------------------------------------------------------------------
           |             Linearized
           |     Margin   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       sex |
        1  |   33.24486   .0730543   455.07   0.000     33.10168    33.38805
        2  |   35.23908   .0774313   455.10   0.000     35.08732    35.39084
------------------------------------------------------------------------------
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/

-----End Original Message-----


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index