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

st: cut and paste spouse's income


From   Ada Ma <[email protected]>
To   [email protected]
Subject   st: cut and paste spouse's income
Date   Tue, 29 Jun 2004 23:00:10 +0100

Hi guys,

I have a problem which I have sorted, but I can't help but wonder if there are better ways of doing it.

I have a data set where I observe the relationship between people within a household and their income. I want to create a variable which carries the value of the spouse's income.

In this example of a household with 5 people, person 1 is the head of the household, person 2 is his spouse, person 3 is his son. Person 4 is the son of person 1 and 2, and the brother of person 3 and 5, so on and so forth. Since person 1 and person 2 are man and wife, cutting and pasting their respective income into each other's spouseinc is pretty straight forward.


houseid person r00 r01 r02 r03 r04 income spouseinc
24 1 . . . . . 10 5
24 2 spouse . . . . 5 10
24 3 son son . . . 6 .
24 4 son son brother . . 2 .
24 5 son son brother brother . 4 .


However, the couple could be placed anywhere in the list. The person records the sequence of the person being interviewed. Wife could be the 3rd to be interviewed, man could be the 5th, etc.

So I created this loop:

sort houseid person
forval i = 1/15 {
local I : di %02.0f `i'-1
replace spouseinc=income[_n-`i'] if (r`I'=="spouse") & /*
*/houseid==houseid[_n-`i']

forval k = 1/`i' {
local j = `i'-`k'
local J : di %02.0f `j'
replace spouseinc=income[_n+`k'] if (r`J'[_n+`k']=="spouse") & /*
*/houseid==houseid[_n+`k']
}
}


OK my codes work. But they look rather clumsy, so my question is - are there prettier, faster ways of doing it?

Ada Ma


--
Ada Ma
Research Assistant
Department of Economics
University of Aberdeen Business School
Edward Wright Building F55
http://www.abdn.ac.uk/economics/

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