Announcement

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

  • How to Run tstf command for intervention analysis

    I am trying to run intervention analysis with an ARIMA model
    I would like to use the following command: tstf OverallInflation if n<209 & n >137, arima(1,1,2) int(185) pulse
    However, I receive an error message that says: the R script did not run, see what's wrong in the file tstf_to_r.R
    I find this strange because I do not use R or have never used R.
    Could someone provide advice on how to effectively conduct my intervention analysis?
    Here is a dataex of my data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int Year str3 Month double(OverallCPI OverallInflation FoodCPI FoodInflation NonFoodCPI NonFoodInflation) float(mdate loginflation n smooth banknote rainfall ehat OverallInflationehat res1)
    2012 "Dec" 412.9 34.6 342.5 34.6  562.1 34.5 635  3.543854 138 34.399998 0 0  1.5791667   1.7480047 -1.8378342
    2013 "Jan" 121.6 35.1 122.5 34.2  123.7   36 636  3.558201 139    35.225 0 1   .7791666    .9447016 -1.0427294
    2013 "Feb" 129.7 37.9 136.1 38.2  126.5 37.6 637  3.634951 140     35.85 0 1   3.079167    3.241398    3.23551
    2013 "Mar" 129.9 36.4 134.4 34.9  125.9 37.9 638  3.594569 141 36.024998 0 1 -1.2208333  -1.0619048 -2.6936135
    2013 "Apr" 127.2 35.8 129.9 33.1  126.1 38.6 639  3.577948 142    34.675 0 1  -.3208333   -.1652079 -.22772422
    2013 "May"   127   31 122.2 25.4  133.8 36.6 640  3.433987 143    31.425 0 0 -4.5208335   -4.368511  -3.991645
    2013 "Jun" 122.3 27.9 112.8 23.5  133.9 32.5 641 3.3286266 144        28 0 0 -2.8208334   -2.671814 -1.3643637
    2013 "Jul" 119.8 25.2 107.7 19.7    134 30.7 642  3.226844 145      25.4 0 0  -2.420833  -2.2751174 -.45695695
    2013 "Aug" 119.1 23.3 105.7 17.8  134.4 28.9 643 3.1484535 146      23.5 0 0 -1.6208333  -1.4784205   -.727733
    2013 "Sep"   126 21.7 117.1 19.2  137.2 24.2 644  3.077312 147    22.475 0 0 -1.3208333  -1.1817237 -.26420733
    2013 "Oct" 129.1 22.2 122.2 19.4  137.8 23.9 645  3.100092 148    22.375 0 0   .7791666    .9149732  1.3043317
    2013 "Nov" 135.1 22.9 131.4 21.3  140.3 24.6 646  3.131137 149    22.875 0 0   .9791667     1.11167   .9789055
    2013 "Dec" 140.6 23.5 139.3   22  142.9 25.1 647     3.157 150    23.525 0 0   .8791667   1.0083668  .24031304
    2014 "Jan" 153.1 25.9   152 24.1    154 30.7 648  3.254243 151    24.025 0 1  2.6791666    2.805064  2.3884115
    2014 "Feb" 161.6 24.6 163.9 20.4    159 29.3 649 3.2027464 152     24.15 0 1 -1.0208334   -.8982394 -2.1360464
    2014 "Mar" 161.2   24 160.7 19.6  161.4 28.9 650  3.178054 153    24.025 0 1  -.3208333   -.2015426    -.35428
    2014 "Apr" 157.7 23.9 152.9 19.5  162.3 28.5 651 3.1738784 154    23.875 0 1  .17916666   .29515427   .7176606
    2014 "May" 165.5 22.6 145.9 19.4  130.8 26.4 652   3.11795 155     23.75 0 0 -1.0208334   -.9081489 -1.2221485
    2014 "Jun" 149.9 22.5 135.2 19.9  164.4 25.7 653 3.1135154 156      23.7 0 0  .17916666   .28854796   .6004669
    2014 "Jul" 146.6 22.3 129.6 20.3  163.4 24.9 654 3.1045866 157      23.7 0 0  .07916667    .1852448   .2083851
    2014 "Aug" 148.3 24.5 131.1   24  165.4 25.8 655  3.198673 158      23.7 0 0   2.479167   2.5819416  2.3356376
    2014 "Sep" 155.9 23.7 143.7 22.7    168 25.4 656  3.165475 159      23.7 0 0  -.5208333   -.4213615 -1.3072298
    2014 "Oct" 159.2 23.3 148.5 21.5  169.8 25.6 657 3.1484535 160      23.7 0 0 -.12083333 -.024664655  -.4591624
    2014 "Nov" 167.1 23.7 159.4 21.3  174.6 26.7 658  3.165475 161      23.7 0 0   .6791667    .7720322   1.149288
    2014 "Dec" 174.5 24.2 170.1 22.1  178.8 27.2 659  3.186353 162    23.075 0 0   .7791666    .8687291   .3352031
    2015 "Jan" 185.6 21.2 184.7 21.5  186.1 20.8 660  3.054001 163     21.45 0 1  -2.720833   -2.634574  -2.962748
    2015 "Feb" 193.5 19.7   195   19  191.6 20.4 661  2.980619 164     19.85 0 1 -1.2208333  -1.1378772  -.4468955
    2015 "Mar" 190.5 18.2 188.1   17  192.6 19.3 662 2.9014215 165    19.025 0 1 -1.2208333  -1.1411804 -.10337662
    2015 "Apr" 187.4 18.8 180.6 18.1  193.9 19.5 663  2.933857 166 18.974998 0 1   .8791667    .9555165  1.1593035
    2015 "May" 186.1 19.5 177.1 21.4  194.9 17.8 664 2.9704144 167    19.775 0 0   .9791667   1.0522133  1.0621831
    2015 "Jun" 181.7 21.3   168 24.2  195.3 18.8 665  3.058707 168    21.075 0 0  2.0791667     2.14891  1.3315547
    2015 "Jul" 179.1 22.2 162.4 25.3  195.6 19.6 666  3.100092 169    22.175 0 0  1.1791667    1.245607    .554446
    2015 "Aug" 182.4   23 166.3 26.8  198.3 19.9 667  3.135494 170    23.075 0 0  1.0791667   1.1423038    .175477
    2015 "Sep" 193.5 24.1   183 27.3  203.8 21.3 668  3.182212 171     23.95 0 0  1.3791667   1.4390007  1.1130346
    2015 "Oct" 198.5 24.7 190.5 28.3  206.2 21.4 669  3.206803 172    24.475 0 0   .8791667    .9356975  .09712333
    2015 "Nov" 208.2 24.6 205.5 28.9  210.5 20.6 670 3.2027464 173      24.6 0 0  .17916666   .23239437 -.16191384
    2015 "Dec" 217.9 24.9 219.7 29.2  215.8 20.7 671  3.214868 174    24.325 0 0  .57916665    .6290912   .3374279
    2016 "Jan" 229.2 23.5 237.3 28.4  220.5 18.5 672     3.157 175     23.75 0 1 -1.1208333   -1.074212 -1.1896832
    2016 "Feb" 238.6 23.4 250.8 28.6    226 17.9 673  3.152736 176    23.375 0 1  .17916666    .2224849  .36166435
    2016 "Mar" 232.5 22.1 237.8 26.5  226.8 17.8 674  3.095578 177        23 0 1 -1.0208334   -.9808183  -.6754782
    2016 "Apr" 226.6 20.9 224.6 24.3  228.4 17.7 675  3.039749 178     22.45 0 1  -.9208333   -.8841214  -.8467293
    2016 "May"   226 21.5 222.5 25.7  229.3 17.6 676  3.068053 179 22.300003 0 0   .8791667    .9125754  1.6336147
    2016 "Jun" 222.9 22.6 214.6 27.7  230.9 18.2 677   3.11795 180     22.55 0 0  1.3791667   1.4092723   .9921772
    2016 "Jul" 221.1 23.5 209.8 29.2  232.1 18.7 678     3.157 181     22.75 0 0  1.1791667    1.205969   .6445929
    2016 "Aug" 223.9 22.8 214.1 28.7  233.5 17.8 679 3.1267605 182      22.4 0 0  -.4208333    -.397334 -1.0995753
    2016 "Sep" 234.4 21.2 232.3   27  236.2 15.9 680  3.054001 183    21.325 0 0 -1.3208333   -1.300637 -1.1931074
    2016 "Oct" 238.3 20.1 238.9 25.4  237.4 15.2 681   3.00072 184     20.35 0 0  -.8208333   -.8039403 -.28367758
    2016 "Nov" 249.7 19.9 256.5 24.8  242.4 15.2 682   2.99072 185        20 0 0  .07916667   .09275654   .6497778
    2016 "Dec" 261.4   20 273.4 24.4    249 15.4 683  2.995732 186      19.5 1 0  .54347825    .3894534    .348541
    2017 "Jan" 270.7 18.2 287.3 21.1  253.4   15 684 2.9014215 187      18.1 1 1 -1.3565217  -1.5138497 -1.6064032
    2017 "Feb" 277.1 16.1 294.8 17.5    259 14.6 685  2.778819 188 16.550001 1 1 -1.6565218   -1.817153 -1.4002457
    2017 "Mar" 269.3 15.8 278.3   17  259.8 14.5 686   2.76001 189    15.575 1 1  .14347826  -.02045607  1.0343033
    2017 "Apr" 259.7 14.6 257.6 14.7  261.4 14.5 687 2.6810215 190    14.325 1 1  -.7565218   -.9237592  -.7890332
    2017 "May" 253.9 12.3 247.4 11.2 260.16 13.5 688  2.509599 191    12.625 1 0 -1.8565217  -2.0270624  -1.706327
    2017 "Jun" 248.1 11.3 234.4  9.3  261.5 13.2 689  2.424803 192    11.275 1 0  -.5565217   -.7303655  .16750912
    2017 "Jul" 243.6 10.2 225.4  7.4  261.5 12.7 690 2.3223877 193     10.25 1 0  -.6565217   -.8336686 -.21772502
    2017 "Aug" 244.8  9.3 227.4  6.2  261.9 12.2 691 2.2300143 194       9.3 1 0 -.45652175   -.6369718  -.3826519
    2017 "Sep" 254.2  8.4 244.3  5.1  263.8 11.6 692 2.1282318 195       8.6 1 0 -.45652175    -.640275 -.16336496
    2017 "Oct"   258  8.3 250.4  4.8  265.3 11.7 693 2.1162555 196  8.275001 1 0   .3434783   .15642187   .3860808
    2017 "Nov"   269  7.7 268.5  4.7  269.1   11 694 2.0412204 197  8.075001 1 0 -.15652174   -.3468813 -.20227936
    2017 "Dec" 279.9  7.1 285.2  4.3  274.1   10 695 1.9600948 198     7.875 1 0 -.15652174   -.3501844  -.3452058
    2018 "Jan"     0  8.1     0  7.6      0  9.6 696  2.091864 199     7.875 1 1  1.4434782   1.2465124   1.582055
    2018 "Feb" 106.8  7.8 110.9  7.3  103.3  9.4 697 2.0541236 200     8.175 1 1  .14347826  -.05679074  -.5092982
    2018 "Mar" 105.8  9.9 107.9 10.6    104  9.7 698 2.2925348 201       8.6 1 1   2.543478   2.3399062  2.2059016
    2018 "Apr" 101.8  9.7  99.3   10  103.9  8.9 699  2.272126 202      8.85 1 1  .24347825   .03660295  -.6424274
    2018 "May" 101.2  8.9  97.7  9.5  104.1  8.4 700 2.1860514 203  8.924999 1 0  -.3565217   -.5667002 -1.0424443
    2018 "Jun"   101  8.6  96.5  9.1  104.6  8.2 701 2.1517622 204     8.975 1 0  .14347826  -.07000335   .4341835
    2018 "Jul" 101.6    9  97.5  9.5    105  8.7 702 2.1972246 205     9.075 1 0   .8434783    .6266935   .6641505
    2018 "Aug"   103  9.3 100.1 10.1  105.5  8.7 703 2.2300143 206     9.275 1 0   .7434782   .52339035   .3886841
    2018 "Sep" 105.1  9.5 103.7 10.2  106.2  8.9 704 2.2512918 207       9.5 1 0   .6434783    .4200872  .13669455
    2018 "Oct" 107.1  9.7 106.2 10.4  107.8  9.2 705  2.272126 208      9.65 1 0   .6434783   .41678405   .3053626
    end
    format %tm mdate
    Thanks in advance!

  • #2
    Here is a simpler dataex:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double OverallInflation float(banknote n)
    34.6 0 138
    35.1 0 139
    37.9 0 140
    36.4 0 141
    35.8 0 142
      31 0 143
    27.9 0 144
    25.2 0 145
    23.3 0 146
    21.7 0 147
    22.2 0 148
    22.9 0 149
    23.5 0 150
    25.9 0 151
    24.6 0 152
      24 0 153
    23.9 0 154
    22.6 0 155
    22.5 0 156
    22.3 0 157
    24.5 0 158
    23.7 0 159
    23.3 0 160
    23.7 0 161
    24.2 0 162
    21.2 0 163
    19.7 0 164
    18.2 0 165
    18.8 0 166
    19.5 0 167
    21.3 0 168
    22.2 0 169
      23 0 170
    24.1 0 171
    24.7 0 172
    24.6 0 173
    24.9 0 174
    23.5 0 175
    23.4 0 176
    22.1 0 177
    20.9 0 178
    21.5 0 179
    22.6 0 180
    23.5 0 181
    22.8 0 182
    21.2 0 183
    20.1 0 184
    19.9 0 185
      20 1 186
    18.2 1 187
    16.1 1 188
    15.8 1 189
    14.6 1 190
    12.3 1 191
    11.3 1 192
    10.2 1 193
     9.3 1 194
     8.4 1 195
     8.3 1 196
     7.7 1 197
     7.1 1 198
     8.1 1 199
     7.8 1 200
     9.9 1 201
     9.7 1 202
     8.9 1 203
     8.6 1 204
       9 1 205
     9.3 1 206
     9.5 1 207
     9.7 1 208
    end

    Comment


    • #3
      See William Lisowski 's explanation in post #6 here.

      Comment


      • #4
        Originally posted by Tom van Oosterhout View Post
        I am trying to run intervention analysis with an ARIMA model
        I would like to use the following command: tstf OverallInflation if n<209 & n >137, arima(1,1,2) int(185) pulse
        However, I receive an error message that says: the R script did not run, see what's wrong in the file tstf_to_r.R
        I find this strange because I do not use R or have never used R.
        For others who find this topic, if you run search tstf to locate and install this package, we see in the output of the search command
        Code:
        1 package found (Stata Journal and STB listed first)
        ----------------------------------------------------
        
        tstf from http://fmwww.bc.edu/RePEc/bocode/t
            'TSTF': module to compute intervention time-series models / tstf fits
            intervention time-series models. The command tstf is / a wrapper for the
            arimax package in R. Therefore R needs to be / installed.  / KW: time
            series / KW: intervention / KW: transfer function / Requires: Stata
        My thanks to Justin Blasongame for linking to my long-forgotten post on this topic.

        Comment


        • #5
          I have now download R but am unsure how to proceed. I try running the command in stata but get the same error code. Do you know the next step I need to take?

          Comment


          • #6
            Everything I know about this was expressed in the topic to which post #3 above linked. If you have followed the process discussed in the linked posts, there is nothing further I can add.

            Comment

            Working...
            X