SOLUTION SET - DAY 3

 

1. What percentage of the entire sample is made up of Indian respondents?  Does the percentage change if you only consider respondents who gave a valid response to the race question?

Commands:

tab race, missing
tab race

Answer:

2.25% of the sample is made up of Indian respondents. Yes, the percentage does change to 2.31%.

 

 

2. Which of the racial groups makes up the largest proportion of urban residents?

Commands:

tab race if metro ~=1

Answer:

Africans have the highest proportion of urban residents.  Of the 2042 urban residents, 55.24% are Africans.

 

 

3. What do respondents think will happen to the quality of their lives under a new government? How many think a new government will improve the situation for their household?  What percent of those surveyed think a new government will not change their household’s quality of life?

Commands:

lookfor government


tab new_govt


replace new_govt = . if new_govt < 0


sort hhid


list hhid new_govt


tab new_govt if hhid[_n] ~= hhid[_n-1]

Answer:

572 households (58.73%) believe a new government will make their lives better. 
169 households (17.35%) believe a new government will not change their household’s quality of life.

 

 

4. What percentage of the sample is made up of grandchildren of the household head?

Commands:

lookfor grandchildren
lookfor relationship


tab rel_head

Answer:  14.50%

 

 

5. How many households located in rural areas report a total monthly income of R300?  Use _n in finding your answer.

Commands:

lookfor total monthly income
lookfor income


sort hhid


list hhid incmon totminc


tab totminc if rural==1 & hhid~=hhid[_n-1]

Answer: 5 households

 

 

6. How many observations do not have a valid hhid value, meaning the observation’s hhid value is missing? Provide three different methods of obtaining the answer to this question, using at least one of the following commands in each – count, codebook, list

Commands:

count if hhid==.
codebook hhid


list hhid if hhid==.

Answer: 0 households

 

 

7. What percent of females live in the old province of Kwa Zulu Natal?  How many of the women living in Kwa Zulu Natal are under the age of 50?

Commands:

tab province if gender_n==2
tab province if gender_n==2 & age<50

Answer:

18.79% of females in the sample data set live in Kwa Zulu Natal.  
47 women in Kwa Zulu are under the age of 50.

 

 

EXTRA CREDIT -  THIS IS VERY HARD

8. Using the system variable <_n>, create a measure that reflects the number of people in the household (i.e. a household size variable) called “size”.  Label the new “size” variable with the following description: “household size”.  You may not use the existing household size variables in constructing your new measure, although you may compare the frequency distribution of “size” with the frequency distribution of the existing household size variables in the data, are they the same?

Commands:

gen temp = 1
replace temp = temp + temp[_n-1] if hhid == hhid[_n-1 ]


gen temp2 = 1


replace temp2 = 0 if temp < temp[_n+1] & hhid == hhid[_n+1]


list hhid temp hhsizep hhsizem if temp2==1


tab temp if temp2==1