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: foreach/forvalue-loop
From
"Künzel Sven" <[email protected]>
To
[email protected]
Subject
st: foreach/forvalue-loop
Date
Sat, 13 Apr 2013 23:05:22 +0200
Dear Statalist,
I tried to program a code. An excerpt from the code can be seen below.
As you can see I tried to program a part of a t-test. At first I
program several "windows" which have different durations. As a second
step I summarize the "averagedeltachange" for every window. And as a
third I drop the variable "t_test_window". As you can see I am
reproducing the same code for every window. Now I would like to
abbreviate the length of the code by using a foreach/forvalue-loop but
I am not quite sure if this is possible at all? And how it would have
to look like?
Thanks for helping me.
/*window t=-10 bis t=-6*/
gen t_test_window=1 if dif >=-10 & dif <=-6 & id==1
egen estimationt_test_window3 = sum(averagedeltachange) if
t_test_window==1
drop t_test_window
/*window t=-5 bis t=-1*/
gen t_test_window=1 if dif >=-5 & dif <=-1 & id==1
egen estimationt_test_window4 = sum(averagedeltachange) if
t_test_window==1
drop t_test_window
/*window t=0 bis t=1*/
gen t_test_window=1 if dif >=0 & dif <=1 & id==1
egen estimationt_test_window5 = sum(averagedeltachange) if
t_test_window==1
drop t_test_window
/*window t=2 bis t=5*/
gen t_test_window=1 if dif >=2 & dif <=5 & id==1
egen estimationt_test_window6 = sum(averagedeltachange) if
t_test_window==1
drop t_test_window
*
* 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/