Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: missings question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: missings question
Date   Thu, 20 Jun 2002 12:43:25 +0100

Riano, Alejandro
>
> I have a panel dataset and i want to filter one of the series using the
> Hodrick-Prescott filter. The problem is that for some countries
> the variable
> that i have to filter has missing observations in a middle year
> (i.e i have
> the observation from 1989 to 1994 and one missing on 1995 and
> then continues
> again). I've ran the following do file:
>
> sort codigo1
> gen hpr=.
> local i=1
> while `i'<codigo1[_N] {
> hpfilter rer if codigo1==`i' & rer~=.
> replace hpr=H_rer if codigo1==`i'
> drop H_
> local i=`i'+1}
> gen devhpr=rer-hpr
>
>
> but when i got to the first country that have the missings in
> between i got
> an error:
> "gaps in the data"
>
> do you know a way in which i could overcome this problem ?? or do you know
> how could i identify the countries for which the missing values for my
> variable are like this:
>
> year  variable
> 89      x89
> 90      x90
> 91      x91
> 92       .
> 93      x93
>
> and so on...
>

It is not mentioned in the help or the original STB insert,
but -hpfilter- cannot operate on data with gaps. It is based
on an optimisation of an objective function based partly on
first differences.

At least three ways are open to you:

1. Decide what would be a reasonable way of dealing with gaps.
Copy the program and amend it.

2. Interpolate missing values first.

3. Use some other smoother. Hodrick-Prescott seems to be,
or to be akin to, a smoothing spline, and you may find
spline code which works with gaps.

Nick
n.j.cox@durham.ac.uk

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index