Announcement

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

  • Regression use if condition from stata

    Can someone help me to explain the inside meaning of using regress with if condition? For example, run the code:
    sysuse auto
    reg price mpg turn if turn>40

    I can get the estimates. I thought it is the same if i run:
    sysuse auto
    drop if turn > 40
    reg price mpg turn

    But they produce different estimates. What is the reason?

    Thanks in advance!

  • #2
    Try
    Code:
    sysuse auto
    keep if turn > 40
    regress price c.(mpg turn)
    and see if that helps.

    Comment


    • #3
      Dong:
      as an aside to Joseph's helpful code, your two codes asks Stata to consider different groups of observations, as you can see from the following toy-example:
      Code:
      . sysuse auto
      (1978 Automobile Data)
      
      .
      .  reg price mpg turn if turn>40
      
            Source |       SS           df       MS      Number of obs   =        35
      -------------+----------------------------------   F(2, 32)        =      5.55
             Model |   105537647         2  52768823.7   Prob > F        =    0.0085
          Residual |   304173759        32  9505429.96   R-squared       =    0.2576
      -------------+----------------------------------   Adj R-squared   =    0.2112
             Total |   409711406        34  12050335.5   Root MSE        =    3083.1
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               mpg |  -610.6069   226.6445    -2.69   0.011    -1072.267   -148.9471
              turn |    25.3587   290.1651     0.09   0.931    -565.6884    616.4057
             _cons |    16480.7   15265.45     1.08   0.288       -14614    47575.41
      ------------------------------------------------------------------------------
      
      .  reg price mpg turn if turn<=40 /// In this second code the -if- qualifier asks Stata to consider only the observations with -turn-<=40
      
            Source |       SS           df       MS      Number of obs   =        39
      -------------+----------------------------------   F(2, 36)        =      5.70
             Model |  45783659.4         2  22891829.7   Prob > F        =    0.0071
          Residual |   144495372        36  4013760.35   R-squared       =    0.2406
      -------------+----------------------------------   Adj R-squared   =    0.1984
             Total |   190279032        38  5007342.94   Root MSE        =    2003.4
      
      ------------------------------------------------------------------------------
             price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
      -------------+----------------------------------------------------------------
               mpg |  -208.8436   63.88249    -3.27   0.002    -338.4033   -79.28385
              turn |   -104.624   154.1457    -0.68   0.502    -417.2461     207.998
             _cons |   14447.08   6426.082     2.25   0.031     1414.379    27479.77
      ------------------------------------------------------------------------------
      Kind regards,
      Carlo
      (StataNow 18.5)

      Comment

      Working...
      X