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

Re: st: RE: posting question.


From   [email protected]
To   [email protected]
Subject   Re: st: RE: posting question.
Date   Thu, 30 Sep 2004 10:52:34 -0400

Nick,
Thnaks for the reply. I try it but get:

. su  mortrate

    Variable |       Obs        Mean    Std. Dev.       Min        Max
-------------+--------------------------------------------------------
    mortrate |      6445    453.0884           0   453.0884   453.0884

. ta  mortrate

   mortrate |      Freq.     Percent        Cum.
------------+-----------------------------------
   453.0884 |      6,445      100.00      100.00
------------+-----------------------------------
      Total |      6,445      100.00


I try also

replace mortrate = $U_1_1 in `i'
but it is not working as well.

Any idea?
Best regards.

Amadou.




                                                                                                                                           
                      "Nick Cox"                                                                                                           
                      <[email protected]>           To:       <[email protected]>                                          
                      Sent by:                         cc:                                                                                 
                      owner-statalist@hsphsun2.        Subject:  st: RE: posting question.                                                 
                      harvard.edu                                                                                                          
                                                                                                                                           
                                                                                                                                           
                      09/30/2004 10:40 AM                                                                                                  
                      Please respond to                                                                                                    
                      statalist                                                                                                            
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           
                                                                                                                                           




I guess that your inner loop
should be more like

forval i=1/`nclust' {
     cap mrate if v001==`i'
     post mortrate (`i') ($U_1_1)
}

Note that you don't need the -mortrate-
variable.

You ask for a -post- of v001. Now
just imagine that you are Stata. v001
is a variable. Stata will not
-post- a whole variable. It shrugs
its shoulders at your funny request
and -post-s v001[1], wherever it is
in the loop.

Put otherwise, the -post- statement
has _no_ consciousness that (a)
it is inside a loop or (b) you
expect it to do different things
each time round the loop, unless
you spell that out.

But you don't need a -post- at
all, given that you want the results
in the same file.

su v001,meanonly
local nclust = r(max)
gen mortrate = .
qui forval i=1/`nclust' {
     cap mrate if v001==`i'
     replace mortrate = $U_1_1 if v001 = `i'

}

Now your results are merged without
using a separate file or -merge-.

Nick
[email protected]

[email protected]
>
> The program mrate, from Macro International, computes
> mortality rates and save
> them in global
> macros. The under-five mortality rate for example is saved in $U_1_1.
> I want to use a DHS survey tdataset and compute mortality
> rates in each cluster.
>
>
> use benin
>
> g id= _n
>
> The cluster variable is v001:
>
> l  v001 in 1/15
>
>      +------+
>       | v001 |
>       |------|
>   1. |    1 |
>   2. |    1 |
>   3. |    1 |
>   4. |    1 |
>   5. |    1 |
>       |------|
>   6. |    1 |
>   7. |    1 |
>   8. |    1 |
>   9. |    1 |
>  10. |    2 |
>        |------|
>  11. |    2 |
>  12. |    2 |
>  13. |    2 |
>  14. |    2 |
>  15. |    2 |
>      +------+
>
> su v001
>     Variable |       Obs        Mean    Std. Dev.       Min        Max
> -------------+--------------------------------------------------------
>         v001 |      5953    130.4614     54.7308          1        210
>
> postfile mortrate v001 double mortrate using mortrate , replace
>
> su v001,meanonly
> local nclust = r(max)
> g mortrate = .
> forval i=1/`nclust' {
>     cap mrate if v001==`i'
>     replace mortrate = $U_1_1
>     post mortrate (v001) (mortrate)
> }
> postclose mortrate
>
> use mortrate, clear
>
> l in 1/15
>
>      +------------------+
>      | v001    mortrate |
>      |------------------|
>   1. |    1   111.11111 |
>   2. |    1   333.33334 |
>   3. |    1         500 |
>   4. |    1   54.054054 |
>   5. |    1           . |
>      |------------------|
>   6. |    1   111.11111 |
>   7. |    1           . |
>   8. |    1           . |
>   9. |    1           . |
>  10. |    1           . |
>      |------------------|
>  11. |    1         100 |
>  12. |    1           . |
>  13. |    1   133.33333 |
>  14. |    1           . |
>  15. |    1   133.33333 |
>      +------------------+
>
> How to get the correct values of v001 so that I can merge
> mortrate.dta with the
> master benin.dta?

*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index