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

st: Help with recoding after reshape long

From   "N. Schenk" <[email protected]>
To   [email protected]
Subject   st: Help with recoding after reshape long
Date   Thu, 13 Dec 2007 17:00:14 +0100 (CET)

Hello to all,

After hours of trying to figure it out myself, I am desperate for help. I
have a wide dataset that has a household grid, where all people in a
certain household are in variables *_1 to *_20, so there can be max 20
members in the household. I want to resort this grid according to type of
household member and then according to age. I do this by reshaping the
grid to long format, so far so good. But, there are certain variables
outside of the grid that refer back to the grid, such as a variable
indicating whether a certain household member has taken care of the
respondent's children. These variables can have max 5 options and have the
household number 1 to 20 denoting the 1 to 20th person in the household
grid. So if ref_1 would be 5 and ref_2 would be 3, meaning that the fifth
and third person in the household grid have taken care of the child.
Because I have resorted the household, these reference  numbers aren't
correct anymore when I'm reshaping back to wide, at variable *_4 there is
a different person than there was originally - given that sorting changed
the order of my grid.
Hence, I want to update these reference variables with the new id's that
the household member will receive when reshaping back to wide. I have the
new id numbers in my data and know what the old ones were. This means that
I have the following datastructure:

id	hhid	ref_1	ref_2	newhhid
1	2	2	3	1
1	1	2	3	2
1	3	2	3	3
2	1	1	2	1
2	3	1	2	2
2	2	1	2	3
3	1	2	1	1
3	2	2	1	2
3	3	2	1	3

I want to update the ref_1 variable with the newid value where oldhhid ==
ref_1, and ref_2 with newid where oldhhid==ref_2. So for respondent 1,
ref_1 would take the new value 1, and ref_2 value 3. For respondent 2,
ref_1 would take on value 1 and ref_2 value 3.
Although I have succeeded in updating the refvar variables on the lines
where ref_1==oldhhid, this doesn't imply though that the entire ref_1
variable is updated. For the first respondent only ref_1[1], and ref_2[3]
are updated. How can I make sure that the entire variable is updated, so
that when I reshape back to wide, these values are constant over

Hopefully I've made myself clear enough.

Thanks so much for any help.

Niels Schenk

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index