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: command forvalues with multiple if expressions
From
Martijn S <[email protected]>
To
[email protected]
Subject
st: command forvalues with multiple if expressions
Date
Tue, 3 May 2011 09:57:25 +0200
Hello all,
I have a problem getting the forvalues command working the way I want.
I have the following problem. I have the following variables:
cftassets3ysd, industrycode and year. Where industrycode has a range
from 1-100 and year a range of 1999 to 2009.
Now I want the following. I want for each industrycode in each year
the mean of cftassets3ysd belonging to that industrycode in that year.
Preferably I want all values be generated in one column. I also have
to note that some observations of cftassets3ysd have missing values,
so as a result I want those to be treated in the right way, thus as
missing values.
Unfortuneatly I cannot get the forvalues loop working.
I hope that someone can help me solving my problem.
Here is a part of my do file of what I want: (year = until 2003 just
to show what I mean)
/* I do not know how to put this in a loop, */
egen sigma_1_1999=mean(cftassets3ysd) if industrycode==1 & year==1999
egen sigma_1_2000=mean(cftassets3ysd) if industrycode==1 & year==2000
egen sigma_1_2001=mean(cftassets3ysd) if industrycode==1 & year==2001
egen sigma_1_2002=mean(cftassets3ysd) if industrycode==1 & year==2002
egen sigma_1_2003=mean(cftassets3ysd) if industrycode==1 & year==2003
egen sigma_2_1999=mean(cftassets3ysd) if industrycode==2 & year==1999
egen sigma_2_2000=mean(cftassets3ysd) if industrycode==2 & year==2000
egen sigma_2_2001=mean(cftassets3ysd) if industrycode==2 & year==2001
egen sigma_2_2002=mean(cftassets3ysd) if industrycode==2 & year==2002
egen sigma_2_2003=mean(cftassets3ysd) if industrycode==2 & year==2003
egen sigma_3_1999=mean(cftassets3ysd) if industrycode==3 & year==1999
egen sigma_3_2000=mean(cftassets3ysd) if industrycode==3 & year==2000
egen sigma_3_2001=mean(cftassets3ysd) if industrycode==3 & year==2001
egen sigma_3_2002=mean(cftassets3ysd) if industrycode==3 & year==2002
egen sigma_3_2003=mean(cftassets3ysd) if industrycode==3 & year==2003
generate industrysigma = sigma_1_1999 + sigma_1_2000 + sigma_1_2001 +
sigma_1_2002 + sigma_1_2003 + sigma_2_1999 + sigma_2_2000 +
sigma_2_2001 + sigma_2_2002 + sigma_2_2003
etc.
Thanks,
Martijn
*
* 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/