Using Stata for Survey Data Analysis
Minot
Page 43
File in original form
hhid
food
quant
value
1
1
3
3
1
3
1
1
1
5
1
1
2
1
1
1
2
5
1
1
3
1
2
2
3
4
1
1
3
5
4
4
If we calculate the average value for each food, it will give the average value among those consuming
the food. If we want the average value including the non-consumers, it is not easy to calculate. Stata
allows you to fill in the “missing” records of foods not consumed by each household. The syntax is
easy:
fillin varlist
where varlist is the list of variables, every combination of which we want to exist in the file. Using
our example above, the command would be
fillin hhid food
Stata will look for all the values of hhid and all the values of food in the file, then it will make sure
every hhid-food combination has a record. When it has to insert record, the values of the other
variables will be missing. The new file would look like this:
File after fillin command
hhid
food
quant
value
1
1
3
3
1
2
.
.
1
3
1
1
1
4
.
.
1
5
1
1
2
1
1
1
2
2
.
.
2
3
.
.
2
4
.
.
2
5
1
1
3
1
2
2
3
2
.
.
3
3
.
.
3
4
1
1
3
5
4
4
If we calculate the average value using this file, we will get the same answer as above. Because
missing values are not counted, the result will be the average among consumers. But if we replace the
missing values with zeros:
recode quant .=0
recode value .=0
Do'stlaringiz bilan baham: |