Hey all,
Wonderful community here. I'm new to coding in stata. I was curious if someone could walk me through how to drop observations of the same value within the variable. I'm working with data in long format where each patient has a separate ID. The ID then repeats itself on a separate row if the patient has multiple study visits.
I want to drop the IDs of all patients (and all of their associated study visits) if they were on a specific drug at the initial visit. To do this, I created a variable, "ondrug" equal 1 if they were on this drug and a corresponding placeholder variable "dropid", where:
dropid = id if ondrug == 1 & followup_num == 1
However, when I run the command:
drop if id == dropid
The only ID that gets dropped is the ID's first visit and al subsequent IDs are left. I tried a for loop and ran into the same issues:
foreach x in dropid {
drop if id == `x'
}
Any idea how I can get stata to drop all of the entries of these patients in long format?
Many thanks!
Related Posts with Dropping observations of a variable
synth_runner's CIsHi everyone, Is there a way to graph confidence intervals when using synth_runner? (to put it around…
Summing across variables with conditionsHello, I am working with a data set where the variables represent questions from a survey that used…
🗎 Temporary file with -tempfile-Dear All, I am looking for a way to make use of temporary files with the putpdf image command. Unfo…
Census data use of weights and survey-designHi! I am using Mexico 2010 census data to do an individual-level analysis. Upon reading the availa…
Question on how to obtain letter of significance after anova (preferably Tukey HSD)?Hi All, I have an anova, where the sex was significantly different (P<0.05), and I run Tukey hsd…
Subscribe to:
Post Comments (Atom)
0 Response to Dropping observations of a variable
Post a Comment