Announcement

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

  • Segmented regression and estimate slopes

    Hi,

    I have a time series and am interested in fitting a segmented regression model to my data to estimate whether there is a change in trends/slopes before and after the introduction of a new policy

    I am basing my analyses on this paper: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5407170/ so I enter 3 predictor terms in the model: time, ban (called ban and coded as 0 before policy introduction, and 1 after that), and a time*ban interaction. I can't share my data so I am using a sample data example, which reflects what I do on my own data:

    clear *
    use http://www.stata-press.com/data/r16/wpi1.dta

    g time = _n
    g ban = time>=101 //policy introduced in 1st quarter 1985

    regress wpi c.time##i.ban

    My understanding is that the coefficient of time captures the trend pre-policy, while the interaction term (time*ban) captures the change post-policy.

    My question is how can I estimate the actual slope post-policy introduction and its standard error?

    Thanks for your help!







  • #2
    you may have to replay your regression with the "coeflegend" option but you can use the -lincom- command for this - just add the two; here is an example using the auto data:
    Code:
    . sysuse auto
    (1978 automobile data)
    r; t=0.01 15:11:58
    
    . regre price c.weight##i.foreign
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =     26.20
           Model |   335885357         3   111961786   Prob > F        =    0.0000
        Residual |   299180039        70  4274000.55   R-squared       =    0.5289
    -------------+----------------------------------   Adj R-squared   =    0.5087
           Total |   635065396        73  8699525.97   Root MSE        =    2067.4
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
          weight |   2.994814   .4163132     7.19   0.000     2.164503    3.825124
                 |
         foreign |
       Domestic  |          0  (base)
        Foreign  |  -2171.597   2829.409    -0.77   0.445    -7814.676    3471.482
                 |
         foreign#|
        c.weight |
        Foreign  |   2.367227   1.121973     2.11   0.038      .129522    4.604931
                 |
           _cons |  -3861.719   1410.404    -2.74   0.008    -6674.681   -1048.757
    ------------------------------------------------------------------------------
    r; t=0.14 15:12:09
    
    . regre price c.weight##i.foreign, coeflegend
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =     26.20
           Model |   335885357         3   111961786   Prob > F        =    0.0000
        Residual |   299180039        70  4274000.55   R-squared       =    0.5289
    -------------+----------------------------------   Adj R-squared   =    0.5087
           Total |   635065396        73  8699525.97   Root MSE        =    2067.4
    
    ------------------------------------------------------------------------------
           price | Coefficient  Legend
    -------------+----------------------------------------------------------------
          weight |   2.994814  _b[weight]
                 |
         foreign |
       Domestic  |          0  _b[0b.foreign]
        Foreign  |  -2171.597  _b[1.foreign]
                 |
         foreign#|
        c.weight |
        Foreign  |   2.367227  _b[1.foreign#c.weight]
                 |
           _cons |  -3861.719  _b[_cons]
    ------------------------------------------------------------------------------
    r; t=0.02 15:12:17
    
    . lincom  _b[weight]+_b[1.foreign#c.weight]
    
     ( 1)  weight + 1.foreign#c.weight = 0
    
    ------------------------------------------------------------------------------
           price | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
    -------------+----------------------------------------------------------------
             (1) |    5.36204   1.041877     5.15   0.000     3.284083    7.439997
    ------------------------------------------------------------------------------

    Comment


    • #3
      Look up the itsa command by Ariel Linden.

      Comment


      • #4
        Thank you both, this is very helpful.

        Rich Goldstein is there a way for me to see what formula is used by -lincom- to estimate the standard error of slope 2?

        Comment


        • #5
          I'm not completely sure I understand what you are asking, but there are two places to start: (1) the manual which you can look at by clicking on the link at the top of the help file; (2) the ado file itself which you an locate with the -which- command

          Comment


          • #6
            Thanks Rich Goldstein

            Comment

            Working...
            X