Announcement

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

  • "mean" command with factor variables in Stata

    Dear all,
    I wonder if any one knows if there is an alternative command that can do the same things as "mean" does, but allowing for the use of factor variables.
    For example, Im looking forward to do something like this:
    Code:
    sysuse auto, clear
    *This is allowed
    mean price
    * But this is not
    mean c.price
    * Much less this
    mean c.price#c.price
    
    * It seems, however, that this is allowed:
    sum c.price#c.price
    * And this:
    sum c.price##c.price
    Thank you in advance.
    Fernando

  • #2
    -summ- accepts factor variable notation, and -mean- does not.

    What exactly do you want to do that cannot be done with -summ-?

    Comment


    • #3
      What do you have against using the sum command? Or with using mean without using factor variable notation?

      reg c,price will work.
      -------------------------------------------
      Richard Williams, Notre Dame Dept of Sociology
      StataNow Version: 19.5 MP (2 processor)

      EMAIL: [email protected]
      WWW: https://www3.nd.edu/~rwilliam

      Comment


      • #4
        Yes that is a great question.
        I was trying to expand on the user written command -oaxaca-, for my own research, to allow for factor variable notation. This program allows to obtain decomposition of the average of an outcome across two groups based on average differences in characteristics or differences in the coefficients of the corresponding models.
        On trying to work on the expansion, so that factor variable notation is allowed, I encounter the problem that to obtain the standard errors of the groups mean for all characteristics, the command calls on "mean". It does that, as far as I understand, to obtain the standard errors also when using complex survey structure.
        In other words, what i want to do is to be able to obtain both the mean and variance covariance matrix of the sample mean characteristics for a set of variables that may or may not include interactions, such that survey weights can be used.
        Thank you again.
        Fernando
        Last edited by FernandoRios; 04 Jan 2019, 09:16.

        Comment


        • #5
          I am not into the example and what exactly what you are doing.

          But -mean- is pretty much a redundant command that I have not used even a single time in my life.

          Just use -regress- as Richard said. Anything that -mean- can do, -regress- can do too, and plenty more.

          Comment


          • #6
            Thank you for your input Joro.
            Actually regress cannot really do what i need it to do, but I think i found a way around it using "fvexpand" and creating all the interactions I needed before using "mean".
            Thank you
            Fernando

            Comment


            • #7
              -mean- fits unconditional mean. -regress- fits conditional mean, but if you condition it on a constant only, you get an unconditional mean.

              So I insist that everything that -mean- can do, -regress- can do too

              But I was wrong in one respect, this would not solve your problem, because for some mysterious reasons -regress- does not accept factor variable notation in the dependent variable... Go figure.

              Code:
              . sysuse auto, clear
              (1978 Automobile Data)
              
              . mean price
              
              Mean estimation                   Number of obs   =         74
              
              --------------------------------------------------------------
                           |       Mean   Std. Err.     [95% Conf. Interval]
              -------------+------------------------------------------------
                     price |   6165.257   342.8719      5481.914      6848.6
              --------------------------------------------------------------
              
              . reg price
              
                    Source |       SS           df       MS      Number of obs   =        74
              -------------+----------------------------------   F(0, 73)        =      0.00
                     Model |           0         0           .   Prob > F        =         .
                  Residual |   635065396        73  8699525.97   R-squared       =    0.0000
              -------------+----------------------------------   Adj R-squared   =    0.0000
                     Total |   635065396        73  8699525.97   Root MSE        =    2949.5
              
              ------------------------------------------------------------------------------
                     price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              -------------+----------------------------------------------------------------
                     _cons |   6165.257   342.8719    17.98   0.000     5481.914      6848.6
              ------------------------------------------------------------------------------
              So far so good, we can reproduce what -mean- does by -regress-.

              Code:
              . mean c.price#c.price
              factor-variable and time-series operators not allowed
              r(101);
              
              . reg c.price#c.price
              depvar may not be an interaction
              r(198);
              So we cannot overcome the defect in -mean- by using -regress-...

              Comment


              • #8
                Just an update to an old question, for anyone seeing this post.
                In Stata 16, one can now use factor notation with the -mean- command.
                Code:
                version 16
                sysuse auto, clear
                replace price=price/1000
                mean c.price##c.price
                
                Mean estimation                      Number of obs   =         74
                
                -----------------------------------------------------------------
                                |       Mean   Std. Err.     [95% Conf. Interval]
                ----------------+------------------------------------------------
                          price |   6.165257   .3428719      5.481914    6.848599
                                |
                c.price#c.price |   46.59236   5.980822      34.67259    58.51212
                -----------------------------------------------------------------

                Comment

                Working...
                X