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: carrying observations forward if criteria met
From
Nick Cox <[email protected]>
To
"'[email protected]'" <[email protected]>
Subject
st: RE: carrying observations forward if criteria met
Date
Thu, 2 Feb 2012 21:00:11 +0000
David Kantor keeps an eye on the list and can speak for his -carryforward- (SSC).
(As always, please explain where user-written programs you refer to come from.)
However, as you say your problem concerns a wide not long data structure, so I think needs to be solved in a different way.
Focusing on S1 as an example, it seems that just you need a loop something like
forval j = 2/8 {
local k = `j' - 1
replace S1_week`j' = S1_week`k' if inrange(S1_week`k', 3, .)
}
Applying the same rule to other symptoms would then be two nested loops.
However, I am queasy about supporting your changing your data, which someone might regret, so advise that you do this on a clone of your data, or equivalently keep a copy of the original variables somewhere.
Also, I have not tested this code, so you should only try it out on a copy of your data.
There was a general review of working "row-wise" in
SJ-9-1 pr0046 . . . . . . . . . . . . . . . . . . . Speaking Stata: Rowwise
(help rowsort, rowranks if installed) . . . . . . . . . . . N. J. Cox
Q1/09 SJ 9(1):137--157
shows how to exploit functions, egen functions, and Mata
for working rowwise; rowsort and rowranks are introduced
Nick
[email protected]
laura hendrix
I have a set of time-series data where patients complete a weekly
survey with items describing the severity of 14 symptoms (scoring
1-lowest to 5-highest) for 8 weeks with. It is in wide format, ie
idno S1_week1 S2_week1 S3_week1....S1_week2 S2_week2 S3_week3....etc
1 3 2 1 ........ 1
2 3
2 1 1 2 ......... 1
3 4
3
4
etc
a score of >=3 is considered clinically relevant. I would like to be
able to read across the weeks for each symptom, and as soon as a score
of 3 or higher is encountered in the 8 week period, the rest of the
values for the period are replaced with this value. for example, if a
patient has a score of 3 in week 2, then the scores for that symptom
will be replaced with 3 for weeks 3,4,5,6,7, and 8. If there is a
higher score in later weeks, it will be overwritten by the first
clinically relevant score.
This is similar to the "carryforward" ado file but I believe that only
replaces missing values?
*
* 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/