Announcement

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

  • How to run a regression per observation

    Dear all,

    I'm trying to determine the degree of conservatisme
    In order to do that I want to use the basu measure of conservatism with the formula NI=b0+b1NEG+ b2RET+ b3RET*NEG.
    I have over 68.000 observations,each observation has a unique company code and fiscal year.
    I would like to run the regression for each observation and capture the b3 als a sort of ranking of conservatism.

    Does anybody know how I can do that?

    The command regress NI NEG RET RET*NEG only give me a b3 for the entire set.
    But iI would like the know the b3 for each observation.


    Is this posible?

    Thank you for your help.

    Kinds regards
    Kimberley


  • #2
    Kimberley:
    welcome to this forum.
    I would say that you're asking for something unfeasible, as you can see from the following toy-example:
    Code:
    . bysort make: regress price mpg if _n<=5
    
    --------------------------------------------------------------------------------------------------------------------
    -> make = AMC Concord
    insufficient observations
    
    --------------------------------------------------------------------------------------------------------------------
    -> make = AMC Pacer
    insufficient observations
    
    --------------------------------------------------------------------------------------------------------------------
    -> make = AMC Spirit
    insufficient observations
    
    --------------------------------------------------------------------------------------------------------------------
    -> make = Audi 5000
    insufficient observations
    
    --------------------------------------------------------------------------------------------------------------------
    -> make = Audi Fox
    insufficient observations
    
    *Conversely:*
    
    . regress price mpg if _n<=5
    
          Source |       SS           df       MS      Number of obs   =         5
    -------------+----------------------------------   F(1, 3)         =      1.02
           Model |  5927544.07         1  5927544.07   Prob > F        =    0.3868
        Residual |  17424499.1         3  5808166.38   R-squared       =    0.2538
    -------------+----------------------------------   Adj R-squared   =    0.0051
           Total |  23352043.2         4   5838010.8   Root MSE        =      2410
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             mpg |  -412.7126   408.5356    -1.01   0.387    -1712.855      887.43
           _cons |    14063.2   8322.503     1.69   0.190    -12422.72    40549.11
    ------------------------------------------------------------------------------
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Dear Carlo,

      thanks for your reaction. I was already afraid of that.

      Do you perhaps have any other idea on how i can calculate the b3?

      Kind regards.

      Kimberley

      Comment


      • #4
        Kimberley:
        you can only calculated the coefficients you're interested in for your whole sample.
        Conversely, Stata can calculate on your behalf the predicted values of the regressand (ie, your dependent variable for each observation, something different from what you asked for in your original post). The reason that supports the unfeasibility of what you were original after rests on the fact that you cannot obtain a sample estimate on an unique observation:
        Code:
        . sysuse auto.dta
        (1978 Automobile Data)
        
        . regress price i.foreign##c.mpg in 1/5
        note: 0.foreign omitted because of collinearity
        note: 0.foreign#c.mpg omitted because of collinearity
        
              Source |       SS           df       MS      Number of obs   =         5
        -------------+----------------------------------   F(1, 3)         =      9.08
               Model |  7761889.59         1  7761889.59   Prob > F        =    0.0571
            Residual |  2564278.41         3  854759.471   R-squared       =    0.7517
        -------------+----------------------------------   Adj R-squared   =    0.6689
               Total |    10326168         4     2581542   Root MSE        =    924.53
        
        -------------------------------------------------------------------------------
                price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
        --------------+----------------------------------------------------------------
              foreign |
            Domestic  |          0  (omitted)
                  mpg |   -447.268   148.4247    -3.01   0.057    -919.6216    25.08551
                      |
        foreign#c.mpg |
            Domestic  |          0  (omitted)
                      |
                _cons |   13645.55   2879.592     4.74   0.018     4481.401    22809.69
        -------------------------------------------------------------------------------
        
        . predict fitted, xb
        
        . list price foreign mpg fitted in 1/5
        
             +-----------------------------------+
             | price    foreign   mpg     fitted |
             |-----------------------------------|
          1. | 4,099   Domestic    22   3805.649 |
          2. | 4,749   Domestic    17    6041.99 |
          3. | 3,799   Domestic    22   3805.649 |
          4. | 4,816   Domestic    20   4700.186 |
          5. | 7,827   Domestic    15   6936.526 |
             +-----------------------------------+
        In addition, your code can be made more efficient via -fvvarlist- notation (see -help fvvarlist- for more details about this wonderful Stata built-in command):
        Code:
        *If your regressors are both continuous*
        regress NI c.RET##c.NEG
        *If your regressors are both categorical*
        regress NI i.RET##i.NEG
        *If your regressors are one continuous and the other one categorical, tweak the previous codes according to your needs*
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment

        Working...
        X