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: Adding up prior iterations of a variable in a time series dataset
From
Benedikt Achatz <[email protected]>
To
[email protected]
Subject
st: Adding up prior iterations of a variable in a time series dataset
Date
Sun, 24 Jun 2012 16:41:47 +0200
Hello,
I am a student and rather new to Stata, and i just can't figure out how
this works. I have been browsing the web for some time and haven't found
a solution that worked for me.
I have a dataset that contains observations of websites at different
points in time. There is a variable, clicks, that contains the clicks in
one time period. What I need to do now is to create a variable
clicks_to_date that contains the clicks in every time period before the
current one, including that one.
This is the code I have been using thus far, without much success...
levelsof page_id, local(pg_id)
levelsof time_var, local(tm_vr)
cap drop clicks_to_date
gen clicks_to_date = 0
local clicks_old = 0
foreach id in `pg_id'{
foreach x in `tm_vr'{
if `x' == 1 {local clicks_old = 0
}
replace clicks_to_date = clicks+`clicks_old'
display `clicks_old'
local clicks_old = clicks_to_date
}
}
Can anyone please hint me into a direction how this could be done?
Thanks,
Ben
*
* 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/