Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: scalar question


From   "Jeffrey W Ladewig" <[email protected]>
To   <[email protected]>
Subject   st: scalar question
Date   Fri, 21 Jul 2006 14:44:08 -0400

I am using a simple while loop statement (see below) to add the mean of each
variable in a series.  The program runs fine except if one of the variables
contains all missing values (there are reasons why I need to keep the
variables).  If, for instance, the 500th variable contains all missing
values, then the scalar (i.e., average_V`i') for the 500th variable equals a
missing value (of course), but the additive scalar (i.e., z) from that point
forward only reports missing values.   That is, my additive scalar stops
adding.  I have been programming a bypass around each of these problematic
variables, but is there a command or something that I could use instead?
Thanks!

Example: 

scalar z = 0
local i = 1
while `i' <= 1000 {

summarize V`i'
scalar average_V`i'= r(mean)
scalar z= z +  average_V`i'

local i = `i' + 1 
}



Jeffrey W Ladewig
Assistant Professor
University of Connecticut
Department of Political Science
341 Mansfield Rd, U-1024
Storrs, CT 06269
w: (860)486-3747
 


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index