Statalist


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

st: generate under bylist


From   Kit Baum <[email protected]>
To   "Uma Radhakrishnan" <[email protected]>
Subject   st: generate under bylist
Date   Thu, 5 Jul 2007 13:06:27 -0400

Uma asked

Household Person BirthNum Yr Desiredcolumn
1 1 1 80 80
1 1 2 0 80
1 1 3 0 80
1 2 1 87 87
1 2 2 0 87
2 1 1 90 90
2 2 1 75 75
2 2 2 0 75
3 1 1 85 85


Each individual is identified by Household and Person (which is not unique). I want to
replace the 0’s in the Yr by the value of Yr when BirthNum=1 for each individual. The
last column in the above table shows what I am trying to do. I am trying to write a loop in
stata to do the above manipulation. I would appreciate it if you could give me guidelines
on how to proceed.


The answer:


+--------------------+
| hh per bn yr |
|--------------------|
1. | 1 1 1 80 |
2. | 1 1 2 0 |
3. | 1 1 3 0 |
4. | 1 2 1 87 |
5. | 1 2 2 0 |
|--------------------|
6. | 2 1 1 90 |
7. | 2 2 1 75 |
8. | 2 2 2 0 |
9. | 3 1 1 85 |
+--------------------+

. bysort hh per (bn): replace yr=yr[1]
(4 real changes made)

. l

+--------------------+
| hh per bn yr |
|--------------------|
1. | 1 1 1 80 |
2. | 1 1 2 80 |
3. | 1 1 3 80 |
4. | 1 2 1 87 |
5. | 1 2 2 87 |
|--------------------|
6. | 2 1 1 90 |
7. | 2 2 1 75 |
8. | 2 2 2 75 |
9. | 3 1 1 85 |
+--------------------+


You might find some useful advice on the use of bylists in my book, URL below.


Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html


On Jul 5, 2007, at 12:10 PM, Uma Radhakrishnan wrote:


Hi Kit,
I am attaching the material in a PDF format.
Thanks.
Uma

On Thu, 5 Jul 2007 11:54:49 -0400
 Kit Baum <[email protected]> wrote:
Please do not send me Word documents; I do not use MS Word. If you want to send me this material please make it into a PDF, which you should be able to do with one click.
Thanks
Kit
Kit Baum, Boston College Economics and DIW Berlin
http://ideas.repec.org/e/pba1.html
An Introduction to Modern Econometrics Using Stata:
http://www.stata-press.com/books/imeus.html
On Jul 5, 2007, at 11:15 AM, Uma Radhakrishnan wrote:

Hi Kit,
I have another issue regarding writing a loop over observations in Stata.
I am attaching a word document with the question I have. I really appreciate the help you have previously given me.
Thanks.
Uma
<Stata Help.doc>
<Stata Help.pdf>

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