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   adiallo5@worldbank.org
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: Trouble with confirm and looping.
Date   Wed, 4 Aug 2004 13:52:21 -0400

Sorry,
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.
Amadou.



                                                                                                                                           
                      "Nick Cox"                                                                                                           
                      <n.j.cox@durham.ac.uk>           To:       <statalist@hsphsun2.harvard.edu>                                          
                      Sent by:                         cc:                                                                                 
                      owner-statalist@hsphsun2.        Subject:  st: RE: Trouble with confirm and looping.                                 
                      harvard.edu                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      08/04/2004 01:37 PM                                                                                                  
                      Please respond to                                                                                                    
                      statalist                                                                                                            
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           




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
n.j.cox@durham.ac.uk

adiallo5@worldbank.org

> 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/




*
*   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/



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