Announcement

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

  • Comparing Slopes

    Hi there,

    In a trend analysis, I am looking at whether hours worked changed across 15 years. Then I am seeing whether hours worked differs by 4 age groups. I already have coefficients (with p-values) for change in hours from baseline to each successive year, but I would like to see whether there is a significant differences between the slopes of each group (i.e. test whether the slopes for two [or more] independent populations are equal). Any ideas how to do this in Stata?

    Code:
    input float(m_yr m_yrqtr2) double m_hrsov_a float m_age_c
    2007 20071   41 3
    2007 20071    . 4
    2007 20071    . 1
    2007 20071    . 3
    2007 20071    . 2
    2007 20071    . 4
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 1
    2007 20071    . 3
    2007 20071   46 2
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 4
    2007 20071    . 3
    2007 20071    . 2
    2007 20071   60 3
    2007 20071    . 3
    2007 20071    . 4
    2007 20071    . 3
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 1
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 4
    2007 20071   40 2
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 1
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 4
    2007 20071    . 4
    2007 20071 40.5 2
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 4
    2007 20071    . 2
    2007 20071    . 4
    2007 20071    . 1
    2007 20071    . 2
    2007 20071   48 3
    2007 20071   55 3
    2007 20071    . 2
    2007 20071    . 4
    2007 20071 25.5 4
    2007 20071    . 3
    2007 20071    . 2
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 2
    2007 20071    . 2
    2007 20071   56 2
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 3
    2007 20071   36 4
    2007 20071    . 4
    2007 20071   50 3
    2007 20071    . 2
    2007 20071   46 3
    2007 20071    . 4
    2007 20071    . 4
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 4
    2007 20071   28 3
    2007 20071    . 2
    2007 20071    . 4
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 4
    2007 20071   40 2
    2007 20071    . 2
    2007 20071    . 4
    2007 20071    . 1
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 3
    2007 20071    . 3
    2007 20071   27 3
    2007 20071    . 2
    2007 20071    . 1
    2007 20071    . 1
    2007 20071    . 2
    2007 20071   50 2
    2007 20071   45 3
    2007 20071   40 3
    2007 20071   46 4
    2007 20071    . 3
    2007 20071    . 2
    2007 20071    . 2
    2007 20071    . 4
    end
    label values m_yr m_yrla
    label values m_hrsov_a m_hrsov_ala
    label values m_age_c m_age_cla
    label def m_age_cla 1 "Gen. Z", modify
    label def m_age_cla 2 "Millennials", modify
    label def m_age_cla 3 "Gen. X", modify
    label def m_age_cla 4 "Baby Boomers", modify
    Thanks in advance for your help!

  • #2
    Olivia:
    what is your regression code?
    What is your regessand?
    Please clarify. Thanks.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo,

      Thanks for responding. It is as follows:

      Code:
      {
          preserve
          
          drop if m_ftemploy_bi == 0
          drop if m_hrsov_a <35
      
      foreach cat of numlist 1/4 {
      
      eststo: areg m_hrsov_a i.m_yr m_wgt m_age /*m_age_sq*/ i.m_sex_bi i.m_mar_c i.m_child_c i.m_cued_bi i.m_ethnic_bi if m_age_c == `cat', absorb (m_region_c) cluster (m_yrqtr2)
      
      esttab using output_age.rtf, replace nogap b(%9.3f) se(%9.3f) parentheses star(* 0.10 ** 0.05 *** 0.01) drop(*cons*)
      
          }
      
          restore
          }
      StataMP 17

      Comment


      • #4
        Olivia:
        an idea that springs to my mind is to take a look at -test- and -lincom-.
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Hi there, thanks for coming back to me.

          I had a little read about those functions, but I wondered how would one use test/lincom when trying to compare differences in the outcome (hours) between different categories in a single variable (age = Gen Z [1]; Millennials [2]; Gen X [3]; Baby Boomers [4])?

          Also using lincom, do I have to run the regression and then immediately run lincom? Are the resulting coefficients somehow stored on the backend? #confused

          Comment


          • #6
            If I understand your question correctly, you want to compare the predicted outcome across levels of a grouping variable in a model with fixed effects. One approach is to estimate an interacted model. I recommend that you install reghdfe from SSC which allows you to absorb multiple fixed effects variables. You need this as you need to interact the fixed effects variables as well. Here is a simplified version of what you want to do.

            Code:
            sysuse auto, clear
            *WHAT YOU ARE DOING NOW
            *ssc install reghdfe, clear
             reghdfe mpg weight displacement if foreign==0, absorb(rep78) nocons
             reghdfe mpg weight displacement if foreign==1, absorb(rep78) nocons
            
            *WHAT I SUGGEST
            **1. INTERACT EACH CATEGORY OF VARIABLE WITH FIXED EFFECTS
            gen rep78xdomestic= rep78#0.foreign
            gen rep78xforeign= rep78#1.foreign
            **2. ESTIMATE INTERACTD MODEL WITH ROBUST SEs
            gen long obsno=_n
            reghdfe mpg i.foreign#(c.weight c.displacement), absorb(rep78xdomestic rep78xforeign) nocons cluster(obsno)
            **3. GENERATE PREDICTIONS WITH MARGINS AND COMPARE WITH TEST
            margins foreign, coefl post
            test _b[0bn.foreign]=_b[1.foreign]
            Res.:

            Code:
            .  reghdfe mpg weight displacement if foreign==0, absorb(rep78) nocons
            (MWFE estimator converged in 1 iterations)
            
            HDFE Linear regression                            Number of obs   =         48
            Absorbing 1 HDFE group                            F(   2,     41) =      47.71
                                                              Prob > F        =     0.0000
                                                              R-squared       =     0.7942
                                                              Adj R-squared   =     0.7641
                                                              Within R-sq.    =     0.6994
                                                              Root MSE        =     2.3087
            
            ------------------------------------------------------------------------------
                     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |  -.0049828   .0011334    -4.40   0.000    -.0072717   -.0026938
            displacement |  -.0032801   .0088741    -0.37   0.714    -.0212018    .0146416
            ------------------------------------------------------------------------------
            
            Absorbed degrees of freedom:
            -----------------------------------------------------+
             Absorbed FE | Categories  - Redundant  = Num. Coefs |
            -------------+---------------------------------------|
                   rep78 |         5           0           5     |
            -----------------------------------------------------+
            
            . 
            .  reghdfe mpg weight displacement if foreign==1, absorb(rep78) nocons
            (MWFE estimator converged in 1 iterations)
            
            HDFE Linear regression                            Number of obs   =         21
            Absorbing 1 HDFE group                            F(   2,     16) =      15.85
                                                              Prob > F        =     0.0002
                                                              R-squared       =     0.6742
                                                              Adj R-squared   =     0.5927
                                                              Within R-sq.    =     0.6646
                                                              Root MSE        =     4.0269
            
            ------------------------------------------------------------------------------
                     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |   .0014993   .0077531     0.19   0.849    -.0149366    .0179352
            displacement |  -.2597622   .1222911    -2.12   0.050    -.5190078   -.0005166
            ------------------------------------------------------------------------------
            
            Absorbed degrees of freedom:
            -----------------------------------------------------+
             Absorbed FE | Categories  - Redundant  = Num. Coefs |
            -------------+---------------------------------------|
                   rep78 |         3           0           3     |
            -----------------------------------------------------+
            
            . 
            . 
            . 
            . *WHAT I SUGGEST
            . **2. ESTIMATE INTERACTD MODEL WITH ROBUST SEs
            
            
            . reghdfe mpg i.foreign#(c.weight c.displacement), absorb(rep78xdomestic rep78xforeign) nocons cluster(obsno)
            (MWFE estimator converged in 2 iterations)
            
            HDFE Linear regression                            Number of obs   =         69
            Absorbing 2 HDFE groups                           F(   4,     57) =      31.07
            Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                              R-squared       =     0.7957
                                                              Adj R-squared   =     0.7563
                                                              Within R-sq.    =     0.6815
            Number of clusters (obsno)   =         69         Root MSE        =     2.8958
            
                                                       (Std. Err. adjusted for 69 clusters in obsno)
            ----------------------------------------------------------------------------------------
                                   |               Robust
                               mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -----------------------+----------------------------------------------------------------
                  foreign#c.weight |
                         Domestic  |  -.0049828   .0014798    -3.37   0.001    -.0079461   -.0020194
                          Foreign  |   .0014993   .0073328     0.20   0.839    -.0131844     .016183
                                   |
            foreign#c.displacement |
                         Domestic  |  -.0032801   .0124683    -0.26   0.793    -.0282475    .0216872
                          Foreign  |  -.2597622   .1153259    -2.25   0.028    -.4906984   -.0288261
            ----------------------------------------------------------------------------------------
            
            Absorbed degrees of freedom:
            --------------------------------------------------------+
                Absorbed FE | Categories  - Redundant  = Num. Coefs |
            ----------------+---------------------------------------|
             rep78xdomestic |         6           0           6     |
              rep78xforeign |         4           2           2     |
            --------------------------------------------------------+
            
            . 
            . **3. GENERATE PREDICTIONS WITH MARGINS AND COMPARE WITH TEST
            
            . 
            . margins foreign, coefl post
            
            Predictive margins                              Number of obs     =         69
            Model VCE    : Robust
            
            Expression   : Linear prediction, predict()
            
            ------------------------------------------------------------------------------
                         |     Margin  Legend
            -------------+----------------------------------------------------------------
                 foreign |
               Domestic  |  -15.75733  _b[0bn.foreign]
                Foreign  |  -46.88705  _b[1.foreign]
            ------------------------------------------------------------------------------
            
            . 
            . test _b[0bn.foreign]=_b[1.foreign]
            
             ( 1)  0bn.foreign - 1.foreign = 0
            
                       chi2(  1) =   11.30
                     Prob > chi2 =    0.0008
            
            .

            Comment

            Working...
            X