Announcement

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

  • Creating IRF plots after ARIMA

    Hello,

    For reasons I cannot figure out, I am able to create IRF plots after an ARIMA regression using the varbasic command, but not using the arima and irf commands. My data and code is as follows.

    Data:
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(year injuries_million_hrs)
    1983 0
    1984 0
    1985 22.963167080003675
    1986 20.50819302311273
    1987 81.9957772174733
    1988 18.352664806929965
    1989 17.903500134276253
    1990 35.12654337249943
    1991 21.644084671659236
    1992 23.458759500797598
    1993 62.786463238525776
    1994 42.98394549635711
    1995 0
    1996 0
    1997 17.462673535318256
    1998 0
    1999 15.519515791107317
    2000 12.670256572695598
    2001 0
    2002 12.90955565309442
    2003 0
    2004 0
    2005 0
    2006 11.513176830882946
    2007 0
    2008 0
    2009 17.809439002671414
    2010 15.291922806373673
    2011 16.838418535731126
    2012 15.557180416621293
    2013 26.243275160740062
    2014 0
    2015 0
    2016 48.19044865307696
    2017 0
    end

    Code:
    tsset year
    varbasic injuries_million_hrs, lags(1/3)
    ^this creates an IRF plot without issue

    tsset year
    arima injuries_million_hrs, ar(1/3)
    irf create naaame, set(naaame) replace
    irf graph irf
    ^this returns the error code "nothing to graph r(198)"

    The reason I would like the arima + irf combination to work is because my full dataset is panel data with N=25102 and T between 1 and 35 years. I am able to run the following arima model on the full panel dataset:
    arima injuries_million_hrs, arima(0,1,3) condition
    but I get the same "nothing to graph" issue when I try and create an irf plot after the arima regression.

    Thank you in advance for any help you are able to provide.
    Last edited by Mia Giuriato; 25 Apr 2019, 15:53.

  • #2
    For reasons that are not clear to me, it appears that the long variable name is the problem. You should pass this along to Technical Support (https://www.stata.com/support/faqs/t...-tech-support/) The code below works:

    Code:
    rename injur hrs
    tsset year
    arima hrs, ar(1/3)
    irf create arima, replace  set(myirf1)
    irf graph irf
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	34.7 KB
ID:	1495209

    Comment


    • #3
      Thank you so much Scott! I will let Technical Support know.

      I have another question. I am hoping to look at the effect of a particular exogenous shock on hrs. When I create the plots, it seems like I am looking at the effect of an unspecified shock to hrs on hrs. How do I specify that a particular shock I have data for should be used?

      Here is the data including the shock:

      Code:
      clear
      input double(year hrs shock)
      1983                  0 0
      1984                  0 0
      1985 22.963167080003675 0
      1986  20.50819302311273 0
      1987   81.9957772174733 0
      1988 18.352664806929965 0
      1989 17.903500134276253 0
      1990  35.12654337249943 0
      1991 21.644084671659236 0
      1992 23.458759500797598 0
      1993 62.786463238525776 0
      1994  42.98394549635711 1
      1995                  0 0
      1996                  0 0
      1997 17.462673535318256 0
      1998                  0 0
      1999 15.519515791107317 0
      2000 12.670256572695598 0
      2001                  0 0
      2002  12.90955565309442 0
      2003                  0 0
      2004                  0 0
      2005                  0 0
      2006 11.513176830882946 0
      2007                  0 0
      2008                  0 0
      2009 17.809439002671414 0
      2010 15.291922806373673 0
      2011 16.838418535731126 0
      2012 15.557180416621293 0
      2013 26.243275160740062 0
      2014                  0 0
      2015                  0 0
      2016  48.19044865307696 0
      2017                  0 0
      end
      If I run:
      Code:
      tsset year
      arima hrs shock, ar(1/3)
      irf create arima, replace set(myirf1)
      irf graph irf

      The plot says that both the impulse and the response are hrs. Am I simply controlling for "shock" here, rather than seeing the effect of this particular shock on hrs? Click image for larger version

Name:	Graph.png
Views:	1
Size:	29.7 KB
ID:	1495248

      Comment


      • #4
        The shock is a one unit change. You could rescale it by just multiplying the one unit change by the scalar factor.

        With the AR(1/3) it is pretty easy to calculate the irf by hand. The general form is irf(j) = ar1*irf(j-1) + ar2*irf(j-2) + ar3*irf(j-3)

        Code:
        arima hrs, ar(1/3)
        
        irf create arima, replace  set(myirf1)
        irf table irf
        
        local IRF0 = 1
        local IRF1 = _b[ARMA:L.ar]*`IRF0'
        local IRF2 =_b[ARMA:L.ar]*(`IRF1') +_b[ARMA:L2.ar]*`IRF0'
        local IRF3 =_b[ARMA:L.ar]*(`IRF2') +_b[ARMA:L2.ar]*`IRF1' +_b[ARMA:L3.ar]*`IRF0'
        disp `IRF1'
        disp `IRF2'
        disp `IRF3'

        Comment


        • #5
          The problem in your first question seems to come from the following lines in arfimairf_create.ado, which is called by irf_create.ado in the case of an ARIMA or ARFIMA model.

          Code:
          qui gen str13 response = "`e(depvar)'"
          qui gen str13 impulse = "`e(depvar)'"
          A quick test shows that a variable name (in -arima-) longer that 13 characters leads to the error.
          If I change these lines to create str25 variables instead, the code runs without error, and apparently correctly.
          However, I am not sure why they were str13 in the first place and whether or not it can break further code.

          HTH

          Jean-Claude Arbaut

          Comment

          Working...
          X