Announcement

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

  • t-testing the same parameter over different groups

    Hello everyone and thanks in advance for the help,
    I have a database which is divided in 4 groups, captured by a variable which takes values 1-4.
    I have to run a regression a check if the parameter of the variable X takes different values between the groups
    My idea is to to run the regression with the option by(group_var). With this, I get the same regression over the 4 sub-samples.
    Then I must find a way to tell Stata to t-test the difference between the _b[X] of each group.
    Any advice?
    Last edited by Daniele Ravasi; 27 Jun 2022, 11:33.

  • #2
    Daniele:
    welcome to this forum.
    If you have a four-level categorical variable and you want to -test- its level each other, the simplest way is the following one:
    Code:
    . use "C:\Program Files\Stata17\ado\base\a\auto.dta"
    (1978 automobile data)
    
    . regress price mpg i.rep78
    
          Source |       SS           df       MS      Number of obs   =        69
    -------------+----------------------------------   F(5, 63)        =      4.39
           Model |   149020603         5  29804120.7   Prob > F        =    0.0017
        Residual |   427776355        63  6790100.88   R-squared       =    0.2584
    -------------+----------------------------------   Adj R-squared   =    0.1995
           Total |   576796959        68  8482308.22   Root MSE        =    2605.8
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             mpg |  -280.2615   61.57666    -4.55   0.000    -403.3126   -157.2103
                 |
           rep78 |
              2  |   877.6347   2063.285     0.43   0.672     -3245.51     5000.78
              3  |   1425.657   1905.438     0.75   0.457    -2382.057    5233.371
              4  |   1693.841   1942.669     0.87   0.387    -2188.274    5575.956
              5  |   3131.982   2041.049     1.53   0.130    -946.7282    7210.693
                 |
           _cons |   10449.99   2251.041     4.64   0.000     5951.646    14948.34
    ------------------------------------------------------------------------------
    
    . test 2.rep78=3.rep78
    
     ( 1)  2.rep78 - 3.rep78 = 0
    
           F(  1,    63) =    0.28
                Prob > F =    0.5990
    
    .
    Conversely, if your gìresearch goal is to compare four different linear regression, see -suest-.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Adding to Carlo's helpful suggestion, you could also like the command

      Code:
      margins rep78, pwcompare(pv)
      To get all pairwise effects.

      Code:
      . margins rep78, pwcompare(pv)
      
      Pairwise comparisons of predictive margins      Number of obs     =         69
      Model VCE    : OLS
      
      Expression   : Linear prediction, predict()
      
      -----------------------------------------------------
                   |            Delta-method    Unadjusted
                   |   Contrast   Std. Err.      t    P>|t|
      -------------+---------------------------------------
             rep78 |
           2 vs 1  |   877.6347   2063.285     0.43   0.672
           3 vs 1  |   1425.657   1905.438     0.75   0.457
           4 vs 1  |   1693.841   1942.669     0.87   0.387
           5 vs 1  |   3131.982   2041.049     1.53   0.130
           3 vs 2  |   548.0223   1037.044     0.53   0.599
           4 vs 2  |   816.2063   1118.251     0.73   0.468
           5 vs 2  |   2254.347   1312.785     1.72   0.091
           4 vs 3  |    268.184   788.9719     0.34   0.735
           5 vs 3  |   1706.325   1040.229     1.64   0.106
           5 vs 4  |   1438.141   1057.152     1.36   0.179
      -----------------------------------------------------
      Best wishes

      Stata 18.0 MP | ORCID | Google Scholar

      Comment


      • #4
        I'm interpreting #1 slightly differently and I suggest interacting X with your 4-category variable; using Carlo's example, as you did not supply any example data, this would be:
        Code:
         
         regress price c.mpg##i.rep78

        Comment

        Working...
        X