Announcement

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

  • ITSA issue

    Hi, I am trying to run an interrupted time series analysis on a single group but after I tsset the data and run the itsa command I get the following error message:
    date_monthly is regularly spaced, but does not have intervals of 1

    Any advice on how to fix this? I have read through itsa help files and tsset files with no luck
    I am able to work around it by setting a daily interval but I want monthly coefficients rather than daily coefficients
    Many thanks in advance!

  • #2
    Can you show your tsset command and Stata output? Better still, show us a sample of the monthly date variable, e.g., by copying and pasting the result of

    Code:
    dataex date_monthly

    Comment


    • #3
      Hi Andrew, thank you for your response. See below

      y Freq. Percent Cum.

      2019m5 556 4.36 4.36
      2019m6 453 3.56 7.92
      2019m7 595 4.67 12.59
      2019m8 602 4.73 17.32
      2019m9 559 4.39 21.70
      2019m10 650 5.10 26.81
      2019m11 590 4.63 31.44
      2019m12 443 3.48 34.91
      2020m1 561 4.40 39.32
      2020m2 562 4.41 43.73
      2020m3 384 3.01 46.74
      2020m4 105 0.82 47.57
      2020m5 328 2.57 50.14
      2020m6 505 3.96 54.11
      2020m7 556 4.36 58.47
      2020m8 634 4.98 63.45
      2020m9 596 4.68 68.12
      2020m10 618 4.85 72.97
      2020m11 562 4.41 77.39
      2020m12 527 4.14 81.52
      2021m1 504 3.96 85.48
      2021m2 509 4.00 89.47
      2021m3 677 5.31 94.79
      2021m4 664 5.21 100.00

      I have to set the data as panel data due to to repeated date times so I created a panel id.

      I use this code: itsa sddnum, single trperiod(2020m5) treatid(3)
      Ideally I want it to be a single group and not panel.
      If I just tsset by month, I get a "repeated time values in sample" error
      I am not sure how to code for a repeated date value as a single group.... any insight is highly appreciated.

      Comment


      • #4
        itsa is from SSC (FAQ Advice #12).

        I have to set the data as panel data due to to repeated date times so I created a panel id.
        What are these data? You cannot arbitrarily create a panel identifier. Whether the data is a time series or a panel, there is temporal sequence and the variation over time is informative. For the command, you need a time-series or a strongly balanced panel, so I think you need to first properly structure your data.

        Comment


        • #5
          Thank you. This data is looking at the efficacy of a policy implementation regarding the sddnum outcome. I don't think it is panel data but it was the only way I could tsset ( other that doing it as daily by sorting the date and creatime abvariable for time equivalent to _n and running a sigle group itsa) We want to compare the trends before and after the policy implementation. However, there are multiple observations within the same month. Additionally, the PI is requesting a monthly coefficient rather than a "daily" coefficient which I can get with the time=_n code described earlier. Not all the observations have the outcome of interest.Outcomes within the same month are assumed to be independent. The PI is requesting interrupted time series to evaluate trends for the time periods...I greatly appreciate any suggestions .

          Comment


          • #6
            Does aggregation make sense for this outcome, e.g., taking monthly averages or choosing the value closest to the median value in the month? I do not know what "sdnumm" is. If it is possible to aggregate the data, you should still be able to determine whether the policy had an effect resulting from an increasing or decreasing trend in the variable. Alternatively, you can still estimate a daily coefficient and convert it into a monthly coefficient through scaling. All these possibilities rely on some underlying assumptions, but that is common in any analysis. As long as you are explicit on what you did and it seems reasonable, you should be fine. But I see no basis for arbitrarily creating a panel dataset with multiple units if the values all belong to the same unit.

            Comment


            • #7
              Thank you Andrew. The outcome is a categorical yes/no. I created a variable showing monthly proportions of yes/no (percentages of yes in a month). I will give it a go with this.
              Many many thanks
              Last edited by Ana Cristina Perez; 15 Dec 2022, 16:36.

              Comment


              • #8
                After aggregation, you should have a time-series which you can tsset. Here is an example where I have a time-series of cigarette sales over a 31 year period. Notice that if I assume that a period consists of 3 years, the coefficient on the treated linear trend without aggregation and with scaling (in red) is very similar to the coefficient when I take period averages (in blue).

                Code:
                use "http://fmwww.bc.edu/repec/bocode/c/cigsales_single.dta", clear
                tsset year
                itsa cigsale, single trperiod(1989) lag(1) fig posttrend
                *CALCULATE SCALED COEFFICIENT (PERIOD=3 YEARS)
                lincom  (_b[_t]+_b[_x_t1989])*3
                *AGGREGATE DATA (3 YEAR PERIODS)
                gen period= floor(year/3)*3
                collapse cigsale, by(period)
                g time=_n
                tsset time
                *NOTE YEAR=1989 == PERIOD=8
                itsa cigsale, single trperiod(8) lag(1) fig posttrend
                Res.:

                Code:
                . itsa cigsale, single trperiod(1989) lag(1) fig posttrend
                
                
                        time variable:  year, 1970 to 2000
                                delta:  1 unit
                
                Regression with Newey-West standard errors      Number of obs     =         31
                maximum lag: 1                                  F(  3,        27) =     331.45
                                                                Prob > F          =     0.0000
                
                ------------------------------------------------------------------------------
                             |             Newey-West
                    _cigsale |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                          _t |  -1.779474   .3834188    -4.64   0.000    -2.566184   -.9927632
                      _x1989 |   -20.0581   4.724395    -4.25   0.000    -29.75175   -10.36444
                    _x_t1989 |  -1.494652   .4368201    -3.42   0.002    -2.390933   -.5983715
                       _cons |   132.2258   4.253054    31.09   0.000     123.4992    140.9523
                ------------------------------------------------------------------------------
                
                
                                    Postintervention Linear Trend: 1989
                
                Treated: _b[_t]+_b[_x_t1989]
                ------------------------------------------------------------------------------
                Linear Trend |      Coef.   Std. Err.      t              [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                     Treated |  -3.274126   .2688039   -12.18   0.000    -3.825666   -2.722586
                ------------------------------------------------------------------------------
                
                .
                . *CALCULATE SCALED COEFFICIENT (PERIOD=3 YEARS)
                
                .
                . lincom  (_b[_t]+_b[_x_t1989])*3
                
                 ( 1)  3*_t + 3*_x_t1989 = 0
                
                ------------------------------------------------------------------------------
                    _cigsale |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                         (1) |  -9.822378   .8064118   -12.18   0.000      -11.477   -8.167758
                ------------------------------------------------------------------------------
                
                .
                . *AGGREGATE DATA (3 YEAR PERIODS)
                
                . itsa cigsale, single trperiod(8) lag(1) fig posttrend
                
                
                        time variable:  time, 1 to 11
                                delta:  1 unit
                
                Regression with Newey-West standard errors      Number of obs     =         11
                maximum lag: 1                                  F(  3,         7) =     218.29
                                                                Prob > F          =     0.0000
                
                ------------------------------------------------------------------------------
                             |             Newey-West
                    _cigsale |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                          _t |  -4.448809   1.595599    -2.79   0.027      -8.2218   -.6758185
                         _x8 |   -24.3019    7.84532    -3.10   0.017    -42.85313   -5.750669
                       _x_t8 |  -5.157858   1.522784    -3.39   0.012    -8.758671   -1.557045
                       _cons |   130.2036   5.829963    22.33   0.000     116.4179    143.9892
                ------------------------------------------------------------------------------
                
                
                                    Postintervention Linear Trend: 8
                
                Treated: _b[_t]+_b[_x_t8]
                ------------------------------------------------------------------------------
                Linear Trend |      Coef.   Std. Err.      t              [95% Conf. Interval]
                -------------+----------------------------------------------------------------
                    Treated |  -9.606668   .6126291   -15.68   0.000    -11.05531    -8.15803
                ------------------------------------------------------------------------------

                Comment


                • #9
                  Thank you so much! I will give it a go.
                  Many thanks again.

                  Comment

                  Working...
                  X