Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Amanda Fu <mandy.fu1@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: how to let loop continue when no observation svy:mean: --capture--gives errors |
Date | Fri, 17 Jun 2011 18:45:54 -0400 |
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/