Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Trouble with confirm and looping.

From   [email protected]
To   [email protected]
Subject   Re: st: RE: Trouble with confirm and looping.
Date   Wed, 4 Aug 2004 13:52:21 -0400

This is a mistake when sending the email.
But I still have the same problem.
The question is how to deal with the missing of
some variables through the loop on the countries.
Many thanks.

                      "Nick Cox"                                                                                                           
                      <[email protected]>           To:       <[email protected]>                                          
                      Sent by:                         cc:                                                                                 
                      owner-statalist@hsphsun2.        Subject:  st: RE: Trouble with confirm and looping.                                 
                      08/04/2004 01:37 PM                                                                                                  
                      Please respond to                                                                                                    

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.

[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:

*   For searches and help try:

© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index