I see a typo here.
Your local macro -country- is not defined, i.e. empty.
You could try
foreach i of local countries {
...
}
except that your loop makes no reference to the
particular country, so I doubt that this code will do
what you want it to. It looks as if it will do the
same each time around the loop.
Nick
[email protected]
[email protected]
> I have to produce a table which compares access to
> electricity by wealth groups
> for a number of african countries using DHS datas.
>
> The wealth index variable is wlthind5, calculated using a
> factor analysis on a set of
> variables (radio, tv, elec, floor, wall, etc...).
>
> wlthind5, as well as the variable used to construct it, are
> available for some countries.
> But in others, some of them contain missings or do not exist at all.
>
> Therefore, I have to reconstruct the wealth index.
>
> local countries "Niger Togo CIV Mali"
> foreach i of local country {
> cap confirm var wlthind5
> if _rc==0 {
> ta wlthind5, m
> }
> else { /*if
> wlthind5 does not
> exist */
> cap confirm var frige bike car radio tv elec floor
> wall rooms
> /*check if these variables exist*/
> if _rc==0 {
> factor frige bike car radio
> tv elec floor wall
> rooms, pcf factors(5)
> score wlthindf
> kdensity wlthindf, normal
> bys hhid: xtile wlthind5
> [aw=hhweight], nq(5)
> ta wlthind5, m
> }
> }
> }
>
> But I just obtain nothing when I run the program (or
> sometimes, depending on the
> country, frige -or another variable used in the factor- does
> not exists).
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/