Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Collapsing records in STATA


From   David Kantor <[email protected]>
To   [email protected]
Subject   Re: st: Collapsing records in STATA
Date   Thu, 15 Jul 2004 17:54:21 -0400

At 04:05 PM 7/15/2004 -0400, Erica Seiguer wrote:
Suppose you have a logit model where you are trying to estimate the
number of children a couple will have. Let's say there are 3 couples, 1,
2 and 3.

In my dataset, for each couple, I have several records which track, year
by year, if they have had a child, and if so, when and the sex of the
child. I want to collapse these separate records into one horizontal
record tracking the couple. Can anyone point me to some stata code that
might assist me?
[...]
It all depends on what you want to do. You can -reshape- (wide), but even then there are several options. You can reshape any yearly information you want by years (that is, j(year) ), but that may give you a very wide dataset (giving you e.g., birth1980, birth1981, etc.) A more concise scheme might be to reshape it into as many births as there are (birth1, birth2, etc. -- keeping whatever information about these births as is relevant).

But either of these options give data schemes that are often useless (directly) for analysis. Presumably, what you need is summary data about the couples. And if all you really want is the number of births, then you do something like this. This assumes that there is a variable whether_birth which is either 0 or 1.

assert whether_birth = 0 | whether_birth = 1
collapse (sum) num_births = whether_birth, by(couple_id)

I hope this helps.



David Kantor
Institute for Policy Studies
Johns Hopkins University
[email protected]
410-516-5404

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




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