Announcement

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

  • tsset with two time variables

    Hi,
    Im trying to fill an unbalanced panel where the observations are unique on an id and two time variables (monthly and year) of the form
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(uniqueid year month)
    1001 1990  1
    1001 1990  2
    1001 1990  3
    1001 1990  4
    1001 1990  5
    1001 1990  6
    1001 1990  7
    1001 1990  8
    1001 1990  9
    1001 1990 10
    1001 1990 11
    1001 1990 12
    1001 1991  1
    1001 1991  2
    1001 1991  3
    1001 1991  4
    1001 1991  7
    1001 1991  8
    1001 1991  9
    1001 1991 10
    1001 1991 11
    1001 1991 12
    1001 1992  1
    1001 1992  2
    1001 1992  4
    1001 1992  5
    1001 1992  6
    1001 1992  7
    1001 1992  8
    1001 1992  9
    1001 1992 10
    1001 1992 11
    1001 1992 12
    1001 1993  1
    1001 1993  2
    1001 1993  3
    1001 1993  4
    1001 1993  5
    1001 1993  8
    1001 1993  9
    1001 1993 10
    1001 1993 11
    1001 1994  1
    1001 1994  2
    1001 1994  3
    1001 1994  5
    1001 1994  7
    1001 1994  8
    1001 1994  9
    1001 1994 10
    1001 1994 11
    1001 1994 12
    1001 1995  1
    1001 1995  2
    1001 1995  3
    1001 1995  4
    1001 1995  5
    1001 1995  6
    1001 1995  7
    1001 1995  8
    1001 1995  9
    1001 1995 10
    1001 1995 11
    1001 1996  1
    1001 1996  2
    1001 1996  3
    1001 1996  4
    1001 1996  7
    1001 1996  9
    1001 1996 10
    1001 1996 11
    1001 1996 12
    1001 1997  1
    1001 1997  2
    1001 1997  3
    1001 1997  4
    1001 1997  5
    1001 1997  7
    1001 1997  8
    1001 1997  9
    1001 1997 10
    1001 1997 12
    1001 1998  1
    1001 1998  2
    1001 1998  3
    1001 1998  4
    1001 1998  5
    1001 1998  6
    1001 1998  7
    1001 1998  8
    1001 1998  9
    1001 1998 10
    1001 1998 11
    1001 1998 12
    1001 1999  1
    1001 1999  2
    1001 1999  3
    1001 1999  5
    1001 1999  8
    1001 1999  9
    end
    [/CODE]

    but the "tsset" command says too many variables are specified. Is the best way to simply create one year/month variable to address this?
    Thank you.

  • #2
    You need a single monthly date variable:

    Code:
    gen mdate = ym(year, month) 
    format mdate %tm 
    tsset uniqueid  mdate

    Comment


    • #3
      Thank you. I am then trying to use "tsfill" to fill the panel such that all id's have an observation for every month year combination from 2000-2010. But after doing so, I see that not every observation is covered. For example,

      uniqueid mdate
      1003 2007m12
      1003 2008m1
      1003 2008m2
      1003 2008m3
      1003 2008m4
      1003 2008m5
      1004 2002m10
      1004 2002m11
      1004 2002m12
      1004 2003m1
      1004 2003m2
      1004 2003m3
      1004 2003m4
      1004 2003m5

      For uniqueid 1004, there are no observations for years 2000-2001, and none for 2009-2010 for uniqueid 1003. Is tsfill not the correct approach for this?

      Comment


      • #4
        tsfill fills in gaps within panels, but never stretches panels beyond the first or last observation. This is explained in the help for tsfill.

        Code:
        tsfill uniqueid mdate, full

        Code:
        fillin uniqueid mdate
        seems to be what you are reaching for, but to what purpose? It can only add missing values on all other variables to the dataset.

        Comment

        Working...
        X