Announcement

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

  • filter hp in 41 quartes by id , loop

    Dear Statlist,

    I have the following problem with calculating Hodrick-Precott filter. What I'm trying to do is applicated the filter hp in a mobile window of 41 quarters

    My dataset have a following structue:

    id dateq lnbankcredit
    12000Q1 23.78
    12000Q2 25.64
    1 2000Q3 24.97
    12000Q4 24.78
    12001Q1 24.99
    12001Q2 24.96
    12001Q3 26.07
    12001Q4 25.41

    22000Q1 23.78
    22000Q2 25.64
    2 2000Q3 24.97
    22000Q4 24.78
    22001Q1 24.99
    22001Q2 24.96
    22001Q3 26.07
    22001Q4 25.41
    ... i have 43 countries- 43 id
    my code is:

    scalar w=40

    foreach x in id {
    preserve
    keep if id==`x'
    drop if lnbankcredit==.
    by id: gen t=_n
    summ t
    local max= r(t)
    forvalues i=1(1) `max'{
    tsfilter hp bankcreditHP_`x'=lnbankcredit if t>=`i' & t<`i'+`w' , smooth(400000) trend(aux_`x')
    replace bankcreditHP_`x'=aux if t=`i'+ `w'
    drop aux
    }
    save temp_`x'.dta, replace
    restore
    }



    I would appreciate any help.

Working...
X