Announcement

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

  • rolling + tsfilter hp

    Dear Statlist,

    I have the following problem with calculating Hodrick-Precott filter. What I'm trying to do is to calculate deviation of some ratio from its trend, measured with the HP filter, using recursive sample.

    Example:

    My dataset have a following structue:

    period ratio
    2000Q1 23.78
    2000Q2 25.64
    2000Q3 24.97
    2000Q4 24.78
    2001Q1 24.99
    2001Q2 24.96
    2001Q3 26.07
    2001Q4 25.41
    ...

    Now, I want to calculate a deviation from a trend in each period. To find the trend, using HP filter, I would normally do:

    tsfilter hp new_var=ratio, smooth(1600) trend(trend)

    But in this way I calculate the trend, using all observations (2000-2001).

    What I want to do is to calculate the trend using only the data available up to the given period. So, for the first period the trend will be equal to the ratio (23.78), for the second period it will be calculated using data available in 200Q1 (23.78) and 200Q2 (25.64), etc.

    I've tried to run the following code:

    rolling,window(100) recursive: tsfilter hp new_var=ratio, smooth(1600) trend(trend)

    but I get a following error:

    (running tsfilter on estimation sample)
    no; data in memory would be lost
    r(4);

    I would appreciate any help.

    Best regards,

    Chris

  • #2
    The syntax for rolling is incorrect - you need the exp_list specifies the statistics to be collected. Also, since the data is changed you need the clear or saving() option.

    It might be easier just to roll your own:

    Code:
    webuse gdp2,clear
    tsfilter hp new_var=gdp_ln in 1/24, smooth(1600) trend(trend)
    tempvar tmp tmp2
    count
    forv i = 25/`=r(N)' {
        qui {
        tsfilter hp `tmp'=gdp_ln in 1/`i', smooth(1600) trend(`tmp2')
        replace new_var = `tmp' in `i'
        replace trend  = `tmp2' in `i'
        drop `tmp' `tmp2'
        }
    }
    ts line new

    Comment


    • #3
      Thank a lot. I'll try the code.

      Best regards,

      Chris

      Comment


      • #4
        Hi Scott,

        I run your codes. every line went fine except last line. It gave an error ''unrecognized command ts''.

        Comment


        • #5
          A little exploration of the help would establish that ts line was a typo for tsline.

          Comment

          Working...
          X