Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: how to let loop continue when no observation svy:mean: --capture--gives errors


From   Stas Kolenikov <[email protected]>
To   [email protected]
Subject   Re: st: how to let loop continue when no observation svy:mean: --capture--gives errors
Date   Fri, 17 Jun 2011 19:46:13 -0400

Looks like this is the case for -collapse (mean) v* [pw=survey
weight], by(a b)-, although generally I dash aside from -collapse- as
it destroys my data. The code you gave won't work for the -matrix-
command that needs to use square brackets. Finally, collecting results
in a matrix is rarely a very good idea... or at least you would want
to provide nice row and column labels to make it readable.

On Fri, Jun 17, 2011 at 6:45 PM, Amanda Fu <[email protected]> wrote:
> Hi all,
>
> I am trying to collect the results for the weighted mean of a set of varaibles.
> ------------------
> ****using matrix stats to collect the results
> matrix stats=J(150,10,-99)
> forvalue i=1/10 {
>        local k=0
>  forvalue j=5/20 {
>     local ++k
>     svy:mean v`i'_`j' if  a==`i' & b==`j'
>        matrix stats(`i',`k')=r(mean)
>   }
>   }
> -------------------
>
> The above codes stop somewhere since "there is no observation" for
> some of the conditions.
> In order to make the loop keep going, I add capture before "svy:mean
> v`i'_`j' if  a==`i' & b==`j'"
> But in the resulted matrix, the places that should be shown as "." are
> filled with the previous nonmissing values. That causes confusion.
> Therefore, I wonder how I can let the loop continue even when there
> are cases that there is no observations ?
>
> Thank you!
>
> Best wishes,
> Amanda
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
>



-- 
Stas Kolenikov, also found at http://stas.kolenikov.name
Small print: I use this email account for mailing lists only.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index