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]

st: Programming Repetition for categories


From   Andrew Hovel <[email protected]>
To   [email protected]
Subject   st: Programming Repetition for categories
Date   Wed, 2 Oct 2013 21:45:25 -0500

I am trying to program repeated calculation of means for my a set of
variables categorized in bins. I am using Stata 12 for windows.

I am new to Stata programming, so I'm guessing there is a better way
to do this than I am attempting, but here goes:

I am calculating means of six variables (Q BRANCH A TYPE P MEMB_TOT)
in my data across 7 different categories of another variable,
SHARE_DEP  (represents a value of  total shares and deposits held by
credit unions)

The categories I use are 0-10million, 10-20million, 20-50 million,
50-100million, 100-250million, 250m-1billion, and >1billion

The code I am using is:
 ***average <10m
if SHARE_DEP < 10000000 {
foreach average in Q BRANCH A TYPE P MEMB_TOT {
 egen avg010_`average' = mean(`average')
 }
}
***average 10-20m
 if SHARE_DEP >= 20000000 & SHARE_DEP < 50000000 {
foreach avg in Q BRANCH A TYPE P  MEMB_TOT{
 egen avg2050_`avg' = mean(`avg')
 }
}
***
and so forth through those >1billion.

The problem here is that the means generated for the first step are
equivalent to the whole population mean, not the mean for observations
where SHARE_DEP < 10000000. (I checked this separately using -sum- for
the variables after dropping all observations where SHARE_DEP >
10000000.)
The subsequent if programs don't even execute.

Any help or suggestions for resolving this would be great.

-AH
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index