Hello,
This is my first post on these forums,
I was wondering how I can link the value on one variable so that it always corresponds to the value on another variabel. As a consequence of working with panel data, one variable of interest can change across each "wave" of surveying of the same respondents, and I need my own variable, constructed in Stata, to follow suit.
A little about the data: I am working with panel data from the China Family Panel Survey, or CFPS. It is conducted every 2 years, and each "wave" is its own seperate dataset when downloaded. Specific individuals are denoted by the variabel "pid", their person-ID. Additionally, in each wave, every individual has a registered "countyid" to denote the county in which they live.
The 2014 CFPS survey, specifically, asks a bunch of questions which I have used to compile an index; I have then taken the average score on this index, sorted by the county for which the respondents live. Essentially, each individual will have a score on this variabel corresponding to the aggregated average score of all respondents living in their county. The idea is to use this as an interaction term later in my work. For that I used the following commands:
But this leaves me with a problem, when merging the datasets: the score is not actually "linked" to each countyid. Because some individuals migrate or move counties between waves, I would only have the score of the county they lived in, in 2014. I don't quite know how to make it so that they would get the correct score corresponding to their countyid in other years. The score of each county should always be the same, since the question was only asked in 2014, but the value that each individual has on the variable should correspond to the county in which they live (based on the 2014 aggregates) and change accordingly.
In other words, a kind of rule so that if an individual has a certain countyid, they will automatically have the corresponding score on countyindex:
countyid == 1 always has countyindex ==0.3
countyid == 2 always has countyindex ==0.5
countyid == 3 always has countyindex ==0.1
So that if an individual has countyid ==1 in 2014, their score on the variable countyindex ==0.3 for that year, but if their countyid ==2 in 2016, their score on the variable countyindex == 0.5 for that year. Is it possible to create this kind of rule that "links" the two variables together?
I hope I have made myself clear; I am not used to asking such technical questions online.
This is my first post on these forums,
I was wondering how I can link the value on one variable so that it always corresponds to the value on another variabel. As a consequence of working with panel data, one variable of interest can change across each "wave" of surveying of the same respondents, and I need my own variable, constructed in Stata, to follow suit.
A little about the data: I am working with panel data from the China Family Panel Survey, or CFPS. It is conducted every 2 years, and each "wave" is its own seperate dataset when downloaded. Specific individuals are denoted by the variabel "pid", their person-ID. Additionally, in each wave, every individual has a registered "countyid" to denote the county in which they live.
The 2014 CFPS survey, specifically, asks a bunch of questions which I have used to compile an index; I have then taken the average score on this index, sorted by the county for which the respondents live. Essentially, each individual will have a score on this variabel corresponding to the aggregated average score of all respondents living in their county. The idea is to use this as an interaction term later in my work. For that I used the following commands:
Code:
by countyid14, sort : egen float countyindex = mean(GVindeks)
But this leaves me with a problem, when merging the datasets: the score is not actually "linked" to each countyid. Because some individuals migrate or move counties between waves, I would only have the score of the county they lived in, in 2014. I don't quite know how to make it so that they would get the correct score corresponding to their countyid in other years. The score of each county should always be the same, since the question was only asked in 2014, but the value that each individual has on the variable should correspond to the county in which they live (based on the 2014 aggregates) and change accordingly.
In other words, a kind of rule so that if an individual has a certain countyid, they will automatically have the corresponding score on countyindex:
countyid == 1 always has countyindex ==0.3
countyid == 2 always has countyindex ==0.5
countyid == 3 always has countyindex ==0.1
So that if an individual has countyid ==1 in 2014, their score on the variable countyindex ==0.3 for that year, but if their countyid ==2 in 2016, their score on the variable countyindex == 0.5 for that year. Is it possible to create this kind of rule that "links" the two variables together?
I hope I have made myself clear; I am not used to asking such technical questions online.
Comment