Friedrich's advice is very good. Nevertheless here is one way to
do what you want:
gen SA = .
gen MA = .
qui forval i = 1/`=_N' {
local M = Mom[`i']
replace SA = S_`M' in `i'
replace MA = A_`M' in `i'
}
>>> [email protected]
The variables S_i, A_i represent characteristics of household member
i. The column Mom gives me the underscored value of where the Mom's
characteristics are. For instance, in the first household, the mom's
characteristics are S_2 and A_2 cause Mom takes the value 2. In the
second household, Mom is in S_1 and A_1...
Id Mom S_1 A_1 S_2 A_2 S_3 A_3 ... S_46 A_46
1 2 0 24 0 22 1 12 ... 0 67
2 1 1 29 0 32 0 8 ... . .
.
.
20 3 1 76 0 75 0 46 ... 1 41
.
.
What I want to create is the following:
Id Mom S_1 A_1 S_2 A_2 S_3 A_3 ... S_46 A_46 SA MA
1 2 0 24 . . 1 12 ... 0 67 0 22
2 1 . . 0 32 0 8 ... . . 1 29
.
.
20 3 1 76 0 75 . . ... 1 41 0 46
*
* 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/