Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: Panel Differences

From   "Jake Kendall" <>
To   <>
Subject   st: Re: Panel Differences
Date   Mon, 1 May 2006 12:03:21 -0700

Hi Alex,

I would create a new variable that uniquely identifies each observation in turn, tsset by that, then 1st difference . Try:

gen unique = _n
tsset unique
gen d_interview=.
replace d_interview= D.interview if D.year ==0
replace d_interview = 365 - L.interview+interview if D.year !=0

*the first line just makes a variable that has the value of the observation number (must be sorted in the right way)
*the rest just fills in the differences accounting for the year change on the last observation in a given year
*you may have to set the first observation by hand as there is no 1st difference

others may have more elegant solutions...

----- Original Message ----- From: "Alexander Nervedi" <>
To: <>
Sent: Monday, May 01, 2006 11:19 AM
Subject: st: Panel Differences


I have data on a panle of 10 kids for 10 years observed approximately every 3 weeks. It kind of looks like as below.

For each child I'd like to get the difference in the date of interviews. Simple things like

gen diff = interview - L1.interview fail me since the tsset command assumes that the day preceeding the current interview date (i,t), is a (i, t-1) where the t-1 is not specific to the i but for anyonein the data set. Consequently interview(i, t-1) may well be missing.

I was wondering what the simplest way would be to get the average distance between interview dates for each of these 10 kids over the 10 year period.



ID year interview
1 1 10
1 1 47
1 1 365
1 2 31
1 2 62
1 2 340
1 10 342
2 1 10


Don't just search. Find. Check out the new MSN Search!

* For searches and help try:

*   For searches and help try:

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