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: RE: foreach/forvalue-loop
From
"Modesto Escobar" <[email protected]>
To
<[email protected]>
Subject
st: RE: foreach/forvalue-loop
Date
Sun, 14 Apr 2013 10:03:30 +0200
I would convert your code into this one:
local dif1 -10 -5 0 2
local dif2 -6 -1 1 5
local wind 3 4 5 6
forvalues i=1/4 {
local p1: word `i' of `dif1'
local p2: word `i' of `dif2'
local pp: word `i' of `wind'
egen estimationt_test_window`pp' = sum(averagedeltachange) if dif >=`p1' & dif <=`p2' & id==1
}
But, maybe you could want one more simple task like this:
recode dif (-10/-6=1)(-5/-1=2)(0/1=3)(2/5=4) (else=.), into(ddif)
tabstat averagedeltachange , statistics(sum) by(ddif)
I hope to be useful.
Modesto Escobar
[email protected]
-----Mensaje original-----
De: [email protected] [mailto:[email protected]] En nombre de Künzel Sven
Enviado el: sábado, 13 de abril de 2013 23:05
Para: [email protected]
Asunto: st: foreach/forvalue-loop
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/
*
* 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/