Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[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 <skolenik@gmail.com>
To   statalist@hsphsun2.harvard.edu
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 <mandy.fu1@gmail.com> 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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index