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

st: re: using explicit subscripts...


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: using explicit subscripts...
Date   Mon, 27 Jun 2005 16:57:33 -0400

Deb Garvey posed a question regarding picking off the value from the head-of-household and applying it to a person in that family with related==1114. If famunit is always 1 for heads-of-household, this would seem to be simple--you don't really need to examine the value of famunit for the head. But I imagine there's more to it than that. But if every family has only one head (check with assert, perhaps), then you can use something like the below to propagate the value to all family members, and use it to replace only the 1114's. Slight modification of Deb's sample data used here.

+-----------------------------------------------+
| pernum related HHhead famunit serial |
|-----------------------------------------------|
1. | 1 101 1 1 2408215 |
2. | 2 201 0 1 2408215 |
3. | 1 101 1 1 2408221 |
4. | 2 301 0 1 2408221 |
5. | 3 1114 0 2 2408221 |
|-----------------------------------------------|
6. | 1 101 1 1 2408222 |
7. | 2 301 0 1 2408222 |
8. | 3 301 0 1 2408222 |
9. | 1 1114 0 2 2408999 |
10. | 2 101 1 1 2408999 |
|-----------------------------------------------|
11. | 3 301 0 1 2408999 |
+-----------------------------------------------+

. g fuhead = HHhead * famunit

. bys serial: egen funew = sum(fuhead)

. replace famunit = funew if related==1114
(2 real changes made)

. l

+----------------------------------------------------------------+
| pernum related HHhead famunit serial fuhead funew |
|----------------------------------------------------------------|
1. | 1 101 1 1 2408215 1 1 |
2. | 2 201 0 1 2408215 0 1 |
3. | 1 101 1 1 2408221 1 1 |
4. | 2 301 0 1 2408221 0 1 |
5. | 3 1114 0 1 2408221 0 1 |
|----------------------------------------------------------------|
6. | 1 101 1 1 2408222 1 1 |
7. | 2 301 0 1 2408222 0 1 |
8. | 3 301 0 1 2408222 0 1 |
9. | 1 1114 0 1 2408999 0 1 |
10. | 2 101 1 1 2408999 1 1 |
|----------------------------------------------------------------|
11. | 3 301 0 1 2408999 0 1 |
+----------------------------------------------------------------+

.

Kit Baum, Boston College Economics
http://ideas.repec.org/e/pba1.html

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