Announcement

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

  • Problem with nlcom after svy:mean

    Hi all,

    I am trying to compute a variance equality test with weighted data. I found this very helpful on Stack Exchange:

    https://stats.stackexchange.com/ques...ed-survey-data

    In which Stas Kolenikov suggests the following code :
    Code:
    webuse nhanes2, clear
    gen bpsystol_sq = bpsystol* bpsystol
    svy : mean bpsystol*, over( female )
    * estimated variance in group 0
    nlcom ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0])
    * estimated variance in group 1
    nlcom ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1])
    * equality test
    testnl ( _b[bpsystol_sq:1] - _b[bpsystol:1]*_b[bpsystol:1]) ///  
       = ( _b[bpsystol_sq:0] - _b[bpsystol:0]*_b[bpsystol:0])
    However, when I run this (and hundreds of variations thereof) I get an error saying equation bpsystol_sq not found.

    The coefficients are indeed stored..
    Code:
     matrix list e(b)
    
    e(b)[1,4]
    c.bpsystol@ c.bpsystol@ c.bpsystol~q@ c.bpsystol~q@
    0.female 1.female 0.female 1.female
    y1 129.92525 124.20266 17255.068 15945.381
    But, attempting to reference them by location gives the following:

    Code:
    testnl (e(b)[1,4] - e(b)[1,2]*e(b)[1,2]) = ( e(b)[1,3] - e(b)[1,1]*e(b)[1,1])
    invalid '2'
    As does various other variations on that theme. I'd be very grateful for any advice.

    Cheers,

    Stu.

  • #2
    it appears that syntax has changed; immediately after estimating your "svy: mean ..." model, try the following to learn how Stata is now referring to the equations:
    Code:
    . svy: mean, coeflegend
    
    Survey: Mean estimation
    
    Number of strata = 31            Number of obs   =      10,351
    Number of PSUs   = 62            Population size = 117,157,513
                                     Design df       =          31
    
    ------------------------------------------------------------------------------
                 |       Mean   Legend
    -------------+----------------------------------------------------------------
      c.bpsystol@|
          female |
           Male  |   129.9253  _b[[email protected]]
         Female  |   124.2027  _b[[email protected]]
                 |
              c. |
     bpsystol_sq@|
          female |
           Male  |   17255.07  _b[[email protected]]
         Female  |   15945.38  _b[[email protected]]
    ------------------------------------------------------------------------------
    you can now use the above info in setting up your -nlcom- statements; here is the first:
    Code:
    nlcom ( _b[[email protected]] - _b[[email protected]]*_b[c.bpsyst
    > [email protected]])

    Comment


    • #3
      Thanks very much indeed. Much appreciated. it's unusual no though for Stata's syntax to change? I confess it didn't occur to me that it might have done as normally one of its selling points is that the code is fully backwards compatible. Perhaps I should start using version!

      Comment

      Working...
      X