Announcement

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

  • Issue with mean x, over(y) command in Stata 16

    There is an issue with the mean command in Stata 16, which does not exist in Stata 15.

    Here is an example:
    mean rel_percapgdp, over(war_year)

    the variable war_year ranges from -20 to 20.
    I get the following error message:

    invalid over() option;
    war_year: factor variables may not contain negative values
    r(452);

    The same command in Stata 15 provides valid results.

    Any suggestions?
    Zeev

  • #2
    In Stata 16, the variables specified in option over() are assumed
    to be factor variables. As such, they can no longer contain fractional
    or negative values. While the old behavior is preserved under version
    control, labeled over() categories will provide much nicer
    looking output in Stata 16 than it did in Stata 15.

    Here is a simple work-around example using the auto data:
    Code:
    sysuse auto
    gen over15 = rep78 - 3
    egen over16 = group(over15) , label
    version 15: mean mpg, over(over15)
    mean mpg, over(over16)
    Here is the log of this example:
    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . gen over15 = rep78 - 3
    (5 missing values generated)
    
    . egen over16 = group(over15) , label
    (5 missing values generated)
    
    . version 15: mean mpg, over(over15)
    
    Mean estimation                   Number of obs   =         69
    
        _subpop_1: over15 = -2
        _subpop_2: over15 = -1
                0: over15 = 0
                1: over15 = 1
                2: over15 = 2
    
    --------------------------------------------------------------
            Over |       Mean   Std. Err.     [95% Conf. Interval]
    -------------+------------------------------------------------
    mpg          |
       _subpop_1 |         21          3      15.01359    26.98641
       _subpop_2 |     19.125   1.328768      16.47348    21.77652
               0 |   19.43333   .7560991      17.92456    20.94211
               1 |   21.66667    1.16316      19.34562    23.98772
               2 |   27.36364   2.632913      22.10974    32.61753
    --------------------------------------------------------------
    
    . mean mpg, over(over16)
    
    Mean estimation                   Number of obs   =         69
    
    --------------------------------------------------------------
                 |       Mean   Std. Err.     [95% Conf. Interval]
    -------------+------------------------------------------------
    c.mpg@over16 |
             -2  |         21          3      15.01359    26.98641
             -1  |     19.125   1.328768      16.47348    21.77652
              0  |   19.43333   .7560991      17.92456    20.94211
              1  |   21.66667    1.16316      19.34562    23.98772
              2  |   27.36364   2.632913      22.10974    32.61753
    --------------------------------------------------------------
    Notice also that the matrix stripe in the modern estimation results uses factor variables notation:
    Code:
    . mean, coeflegend
    
    Mean estimation                   Number of obs   =         69
    
    ------------------------------------------------------------------------------
                 |       Mean  Legend
    -------------+----------------------------------------------------------------
    c.mpg@over16 |
             -2  |         21  _b[[email protected]]  
             -1  |     19.125  _b[[email protected]]
              0  |   19.43333  _b[[email protected]]
              1  |   21.66667  _b[[email protected]]
              2  |   27.36364  _b[[email protected]]
    ------------------------------------------------------------------------------
    Last edited by Jeff Pitblado (StataCorp); 01 Nov 2019, 09:25.

    Comment

    Working...
    X