Announcement

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

  • tsfill

    Dear all,

    In the data below ( actual data has more observations), I want to fill in the value of Xindex for the missing years by cnum which is a firm unique id, that is, 5 should be assigned to year 1991 1992 for "000209" , I will not fill in data for the time period after the last year, that is if a firm e.g. "000209" has data 1990 to 1993, I will not fill in after 1993.

    What I need : for each firm it could have different starting year and ending year. just want to fill in the gap between these two. for ""000361" , it should have no missing values between 1990 and 2006 after fill in.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year byte xindex str6 cnum
    1993 5 "000209" 
    1990 5 "000361" 
    1993 5 "000361" 
    1995 5 "000361" 
    1998 5 "000361" 
    2000 5 "000361" 
    2002 5 "000361" 
    2004 5 "000361" 
    2006 5 "000361" 
    end
    Thanks a lot,

    Rochelle

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year byte xindex str6 cnum
    1993 5 "000209" 
    1990 5 "000361" 
    1993 5 "000361" 
    1995 5 "000361" 
    1998 5 "000361" 
    2000 5 "000361" 
    2002 5 "000361" 
    2004 5 "000361" 
    2006 5 "000361" 
    end
    
    egen long ncnum = group(cnum)
    xtset ncnum year
    tsfill
    by ncnum (year cnum), sort: replace cnum = cnum[_N] if missing(cnum)
    by ncnum (year xindex), sort: replace xindex = xindex[1] if missing(xindex)
    should do it.

    Comment


    • #3
      Thank you Clyde !

      I see you generate a numeric variable that allows us to xtset, very clever !

      Comment

      Working...
      X