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

From |
n j cox <n.j.cox@durham.ac.uk> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: expand and duration model |

Date |
Sun, 17 Feb 2008 17:26:48 +0000 |

This is not the problem tackled by -expand-. Nor does -expandby- (a user-written program from SSC) claim to tackle anything like this problem.

The problem has presumably been solved before, but off-hand I can't remember any program that does it. However, a few lines should get

you most of the way.

expand 2

sort id datealt

by id: replace datealt = datebax[_n - 1] + 1 if mod(_n, 2) == 0

by id: replace datebax = datealt[_n + 1] - 1 if mod(_n, 2) == 0

by id: replace y = 0 if mod(_n, 2) == 0

by id: replace x = 0 if mod(_n, 2) == 0

by id: drop if _n == _N

Consider -id- 1.

1 11/02/2001 14/08/2003 100 205

1 02/03/2005 05/06/2005 120 130

1 13/08/2005 18/12/2005 100 130

We -expand 2- and then -sort- to get this:

_n

1 11/02/2001 14/08/2003 100 205 1

1 11/02/2001 14/08/2003 100 205 2

1 02/03/2005 05/06/2005 120 130 3

1 02/03/2005 05/06/2005 120 130 4

1 13/08/2005 18/12/2005 100 130 5

1 13/08/2005 18/12/2005 100 130 6

We need to work on the even-numbered observations, those with _n

of 2, 4, ... -- which are identified by -mod(_n, 2) == 0-.

We look backwards for the start date of each gap, and add 1; and forwards for the end of each gap, and subtract 1.

A correction is that the last observation for each -id- will contain no useful information, so we -drop- it. On the other hand, you might know that your study ended at some time. Suppose your study ended on 31/12/2007. Then instead of

by id: drop if _n == _N

you should have

by id : replace datebax = mdy(12,31,2007) if _n == _N

You need to modify this if the recipe has to cope with gaps of length 0. Look for observations with -datebax < datealt- and -drop- them.

I have not tested this code, but I hope it helps.

Nick

n.j.cox@durham.ac.uk

Catia

=====

I have a problem to understand how to expand my observation to stset

my data to use in a

duration model.

I have the following data set:

id datealt datebax y x

1 11/02/2001 14/08/2003 100 205

1 02/03/2005 05/06/2005 120 130

1 13/08/2005 18/12/2005 100 130

2..........

2..........

so I want a dataset for the period that I don't observe the id:

id datealt datebax y x

1 11/02/2001 14/08/2003 100 205

1 15/08/2003 01/032005 0 0

1 02/03/2005 05/06/2005 120 130

1 06/06/2005 12/082005 0 0

1 13/08/2005 18/12/2005 100 130

2.........

2.......

2..........

Someone can help me?

I try with expandby but without results.

*

* 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/

**Follow-Ups**:**Re: st: expand and duration model***From:*ncdcta00@uniroma2.it

- Prev by Date:
**st: RE: ST: Zero Inflated Poisson model for panel data** - Next by Date:
**st: summation within a nonlinear regression** - Previous by thread:
**st: expand and duration model** - Next by thread:
**Re: st: expand and duration model** - Index(es):

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