Statalist The Stata Listserver


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

Re: st: RE: programming in Stata


From   Antoine Terracol <[email protected]>
To   [email protected]
Subject   Re: st: RE: programming in Stata
Date   Thu, 15 Mar 2007 12:14:21 +0100

Are you sure you correctly specified the -bysort- part of the command ?

Ali Khashan wrote:
Many Thanks to those who responded.
The suggested commands work but they are not enough. They do not take into
account that we have different mothers. for example for mother_number
1234567892 newvar will be 40 when it must be missing because this mother has no
previuos child. Is there another code to work only when the mother_number is
repeated.

Many Thanks
Ali


Quoting Maarten Buis <[email protected]>:


--- Ali Khashan wrote:
I have a large dataset similar to this:
mother_number child_number GA nDate suggested var
1234567891 23456789 35 21 Feb 1975 .
1234567891 23456781 37 30 May 1978 35
1234567891 23456782 40 04 Oct 1982 37
1234567892 56789012 37 17 Mar 1976
1234567893 56489023 40 23 Sep 1985
1234567894 34567891 40 19 Nov 1977
1234567894 45567890 42 13 May 1979

From mother_number you can see that some women have more than one child (they
have the same identification number). GA is gestational age and nDate is date
of birth of the child. I need to generate another variable which indicates
gestational age of the previuos child.

*---------------------- begin example ------------
clear
input double mother_number double child_number GA
1234567891            23456789      35
1234567891            23456781      37
1234567891            23456782      40
1234567892            56789012      37
1234567893            56489023      40
1234567894            34567891      40
1234567894            45567890      42
end

bys mother_number (GA): gen prevGA = GA[_n-1]
list
*-------------------- end example -------------------
(For more on how to use examples I sent to the Statalist, see
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )

-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------



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



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


--
Ce message a ete verifie par MailScanner
pour des virus ou des polluriels et rien de
suspect n'a ete trouve.

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