Code:
bysort personid: egen mhealth35 = mean(health) if inrange(age,3,5)
This seems to be because the code I used only displays the averages for when the respondent is within the ages specified within inrange(3,5). For example, if a person's average health status between the ages of 3 and 5 is 3.67, then the mean health status variable (mhealth35) only takes on the of 3.67 when the respondent is 3, 4, and 5 years old. However, when the respondent is not any of those ages, the value is missing. I'd like for the value to not be missing. How would I do that? I hope this is clear. Please let me know if I should clarify.
Below is an example of what my data looks like after using the code displayed above to generate the average health status variables for two separate age intervals (3-5 and 25-27). Rather than display the full set of ages available, I've truncated the observations for convenience.
What my data looks like:
Individual Id | Health Status | Average Health Status between ages 3 and 5 | Age | Average Health Status between ages 25 and 27 |
10001 | 2 | 3.67 | 3 | missing |
10001 | 4 | 3.67 | 4 | missing |
10001 | 5 | 3.67 | 5 | missing |
10001 | 4. | missing | 25 | 4.33 |
10001 | 4 | missing | 26 | 4.33 |
10001 | 5 | missing | 27 | 4.33 |
10001 | 2 | missing | 28 | missing |
10001 | 5 | missing | 29 | missing |
10001 | 3 | missing | 30 | missing |
Below is an example what I want my data to look like:
Individual Id | Health Status | Average Health Status between ages 3 and 5 | Age | Average Health Status between ages 25 and 27 |
10001 | 2 | 3.67 | 3 | 4.33 |
10001 | 4 | 3.67 | 4 | 4.33 |
10001 | 5 | 3.67 | 5 | 4.33 |
10001 | 4. | 3.67 | 25 | 4.33 |
10001 | 4 | 3.67 | 26 | 4.33 |
10001 | 5 | 3.67 | 27 | 4.33 |
10001 | 2 | 3.67 | 28 | 4.33 |
10001 | 5 | 3.67 | 29 | 4.33 |
10001 | 3 | 3.67 | 30 | 4.33 |
0 Response to Trouble with Creating Group-Level variable
Post a Comment