Announcement

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

  • Error "pweights must be positive"

    Hi Statalists,

    I keeps getting an error message, ""pweights must be positive", when using the "mixed" command.

    Click image for larger version

Name:	1.png
Views:	1
Size:	18.0 KB
ID:	1590987


    I have checked that the values of weights for both levels are all positive. I'm using Stata 14 version. I'm not sure why it keeps showing this error message.

    The same question has been asked in the forum in the post from 2018, 2016, and 2014

    However, my question is: is there any way I can apply the pweights without changing the "mixed" command to "svy"?

    Thank you for your help.

  • #2
    Note that in the 2014 link, the summary statistics do indicate that some probability weights (pw) are equal to 0. Therefore, the error message is not misleading. While Stata will allow you to have some pw=0 at the first level of the multilevel model using the standard weight syntax [pw= mypweights1], it will not allow you to do this for the second or higher levels where you specify this as an option -pweight(mypweights2)-. Essentially, including observations with a probability weight of 0 has the same effect as excluding these observations, so all you need to do is to drop such observations before estimating the model.

    Code:
    webuse pig, clear
    set seed 01242021
    gen mypweights1=runiformint(0,7)
    gen mypweights2= runiformint(0,5)
    bysort id: replace mypweights2= mypweights2[1]
    *REPLICATE ERROR
    mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size)
    *DROP OBS WITH pw2=0
    preserve
    drop if mypweights2==0
    mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size) nolog
    restore
    Res.:

    Code:
    . *REPLICATE ERROR
    
    . mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size)
    pweights must be positive
    r(111);
    
    . 
    . *DROP OBS WITH pw2=0
    
    . drop if mypweights2==0
    (72 observations deleted)
    
    . 
    . mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size) nolog
    
    Mixed-effects regression                        Number of obs     =        360
    Group variable: id                              Number of groups  =         40
    
                                                    Obs per group:
                                                                  min =          9
                                                                  avg =        9.0
                                                                  max =          9
    
                                                    Wald chi2(1)      =    2998.50
    Log pseudolikelihood = -2113.6401               Prob > chi2       =     0.0000
    
                                        (Std. Err. adjusted for 40 clusters in id)
    ------------------------------------------------------------------------------
                 |               Robust
          weight |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
            week |   6.218758   .1135668    54.76   0.000     5.996171    6.441345
           _cons |   19.29656   .5339448    36.14   0.000     18.25005    20.34307
    ------------------------------------------------------------------------------
    
    ------------------------------------------------------------------------------
                                 |               Robust           
      Random-effects Parameters  |   Estimate   Std. Err.     [95% Conf. Interval]
    -----------------------------+------------------------------------------------
    id: Unstructured             |
                       var(week) |   .3892068   .1017598      .2331471    .6497269
                      var(_cons) |   8.923591   2.407496      5.258888    15.14207
                 cov(week,_cons) |  -.1793636   .3347646     -.8354902     .476763
    -----------------------------+------------------------------------------------
                   var(Residual) |    1.59087   .2061186        1.2341    2.050781
    ------------------------------------------------------------------------------

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Note that in the 2014 link, the summary statistics do indicate that some probability weights (pw) are equal to 0. Therefore, the error message is not misleading. While Stata will allow you to have some pw=0 at the first level of the multilevel model using the standard weight syntax [pw= mypweights1], it will not allow you to do this for the second or higher levels where you specify this as an option -pweight(mypweights2)-. Essentially, including observations with a probability weight of 0 has the same effect as excluding these observations, so all you need to do is to drop such observations before estimating the model.

      Code:
      webuse pig, clear
      set seed 01242021
      gen mypweights1=runiformint(0,7)
      gen mypweights2= runiformint(0,5)
      bysort id: replace mypweights2= mypweights2[1]
      *REPLICATE ERROR
      mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size)
      *DROP OBS WITH pw2=0
      preserve
      drop if mypweights2==0
      mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size) nolog
      restore
      Res.:

      Code:
      . *REPLICATE ERROR
      
      . mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size)
      pweights must be positive
      r(111);
      
      .
      . *DROP OBS WITH pw2=0
      
      . drop if mypweights2==0
      (72 observations deleted)
      
      .
      . mixed weight week [pw=mypweights1] || id: week , cov(un) pweight(mypweights2) pwscale(size) nolog
      
      Mixed-effects regression Number of obs = 360
      Group variable: id Number of groups = 40
      
      Obs per group:
      min = 9
      avg = 9.0
      max = 9
      
      Wald chi2(1) = 2998.50
      Log pseudolikelihood = -2113.6401 Prob > chi2 = 0.0000
      
      (Std. Err. adjusted for 40 clusters in id)
      ------------------------------------------------------------------------------
      | Robust
      weight | Coef. Std. Err. z P>|z| [95% Conf. Interval]
      -------------+----------------------------------------------------------------
      week | 6.218758 .1135668 54.76 0.000 5.996171 6.441345
      _cons | 19.29656 .5339448 36.14 0.000 18.25005 20.34307
      ------------------------------------------------------------------------------
      
      ------------------------------------------------------------------------------
      | Robust
      Random-effects Parameters | Estimate Std. Err. [95% Conf. Interval]
      -----------------------------+------------------------------------------------
      id: Unstructured |
      var(week) | .3892068 .1017598 .2331471 .6497269
      var(_cons) | 8.923591 2.407496 5.258888 15.14207
      cov(week,_cons) | -.1793636 .3347646 -.8354902 .476763
      -----------------------------+------------------------------------------------
      var(Residual) | 1.59087 .2061186 1.2341 2.050781
      ------------------------------------------------------------------------------

      Thank you so much for your help! Yes, it worked!

      Comment

      Working...
      X