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]

From |
Amanda Fu <mandy.fu1@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 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 <skolenik@gmail.com> 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 <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/ > * * 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/

**References**:**st: how to let loop continue when no observation svy:mean: --capture--gives errors***From:*Amanda Fu <mandy.fu1@gmail.com>

**Re: st: how to let loop continue when no observation svy:mean: --capture--gives errors***From:*Stas Kolenikov <skolenik@gmail.com>

- Prev by Date:
**Re: st: Nlsur quaids and IV** - Next by Date:
**st: nl estimation: Error #130 Expression too long** - Previous by thread:
**Re: st: how to let loop continue when no observation svy:mean: --capture--gives errors** - Next by thread:
**st: how to let loop continue when no observation svy:mean: --capture--gives errors** - Index(es):