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   Amanda Fu <[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 21:23:58 -0400

Dear Mr. Kolenikov,

Thank you for suggestion of using collapse! It is smart way. It never
occurred to me because I do not like collapse neither because of the
same reason!

I borrowed the idea of Using matrix to collect results from Scott
Long's workflow Stata book. You are absolutely right: I need to make
the rownames and column  names readable.

Thanks again for helping me out!
Sincerely,
Amanda Fu

On Fri, Jun 17, 2011 at 7:46 PM, Stas Kolenikov <[email protected]> wrote:
> 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/
>

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