Announcement

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

  • HP filter panel data

    Hello,
    I am PhD student and I am new to stata. I am trying to create an hp trend for variable TourPrice in my panel dataset.
    I got an error message after using the "tsfilter hp" command saying that " Number of gaps in sample: 1 (gap count includes panel changes) sample may not contain gaps".

    Here are the commands that I typed:

    egen countryid = group(CountryCode), label lname(countryid)
    xtset countryid Time
    iis countryid
    tis Time

    tsfilter hp TPcycleHP=TourPrice, trend(TPtrendHP)

    By looking at the data browser, for the first few countries in the dataset, the HP trend was calculated (two variables TPcycleHP and TPtrendHP). The missing observations are automatically excluded and the Trend is calculated for the existing observations.

    However, it suddenly stops. Starting the country Bhutan, the trend is no longer calculated, even for existing observations of the variable TourPrice. I don't understand where the problem is.
    Is it because the panel is unbalanced? I dnt think that the missing observations are an issue since it already did it for the first few countries in the database.

    What can I do at this point? I looked at the forums concerning this topic. Some advised to create a new time variable. (gen time =_n) and then try again. I did and it gave me the same error message.

    Thank you in advance for your help.

    Sincerely,
    Rajwane

  • #2
    Welcome to Statalist.

    I will guess that for the first few countries, the missing observations were at the beginning or end (or both) of the series, while for Bhutan there is a missing observation in the middle of the series - hence the "gap" that Stata reported - and that is why your command ceased running.

    The commands
    Code:
    xtdescribe
    tsreport, panel detail
    may help you confirm this diagnosis and locate problem, but looking at the data for Bhutan might might be sufficient for a gap in its data to become apparent.

    By the way, the iis and tis commands are not needed, the output of help iis tells us that they have been replaced by the xtset command you are already using.

    Comment


    • #3
      Dear William,
      Thank you for your response.
      I tried the tsreport command. This is what I got:

      xtdescribe

      countryid: 1, 2, ..., 232 n = 232
      Time: 1995, 1996, ..., 2017 T = 23
      Delta(Time) = 1 unit
      Span(Time) = 23 periods
      (countryid*Time uniquely identifies each observation)

      Distribution of T_i: min 5% 25% 50% 75% 95% max
      22 23 23 23 23 23 23

      Freq. Percent Cum. | Pattern
      ---------------------------+-------------------------
      228 98.28 98.28 | 11111111111111111111111
      4 1.72 100.00 | 1111111111111111111111.
      ---------------------------+-------------------------
      232 100.00 | XXXXXXXXXXXXXXXXXXXXXXX


      tsreport, panel detail

      Panel variable: countryid
      Time variable: Time
      ----------------------------
      Starting period = 1995
      Ending period = 2017
      Observations = 5,332
      Number of gaps = 0

      I'm surprised that the number of gaps=0. For Bhutan, I have no obervations for TourPrice (the variable for which I am generating the trend). But it was the same for Afghanistan and other countries at the beginning of the data. I'm a bit confused on why it stopped on Bhutan in particular. I checked the country Botswana that comes right after Bhutan to see if there are any problems or gaps, but nothing either. Botswana has observations for TourPrice from 1995 till 2017, but only the year 2001 missing. I believe this is the problem, right?

      Thank you in advance.
      Rajwane
      Last edited by Rajwane Kafrouni; 20 Jan 2020, 13:52.

      Comment


      • #4
        I am a bit confused.

        In post #1 you wrote

        Starting the country Bhutan, the trend is no longer calculated, even for existing observations of the variable TourPrice
        But in post #3 you wrote

        For Bhutan, I have no observations for TourPrice
        These seem contradictory. What am I not understanding?

        I believe that both Afghanistan and Bhutan have some observations with values for TourPrice, and some observations with missing values for TourPrice. For Afghanistan the missing values are all at the beginning or end of the series, while for Bhutan there is a missing value between two non-missing values.

        You could
        Code:
        list countryid Time TourPrice if countryid==???
        where you replace ??? with whatever the countryid is for Bhutan. This should show you where the "gap" - missing value - is in the middle of the series.

        Comment


        • #5
          Sorry I was not clear. I meant for the countries starting Bhutan. Not just for Bhutan itself.

          The problem is like you mentioned in your first reply, the missing observations between two non-missing values.

          I fixed the problem by completing or removing the missing values between non-missing values and it worked!

          Thank you so much for your help!

          Comment

          Working...
          X