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
Error while using _N in forvalues loopI want to use _N in place of the total count of observations in a loop like this: forvalues i = 1(1…
Coding questionI am running into a wall on applying a predicted class of a state (all 50 states have one of four pr…
Birth OrderHi Everyone I am working on India Human Development Survey (IHDS). It is a cross sectional Data. I h…
How to use marker symbols with twoway graphDear Statalists, I have two questions that I am sure are relatively easy for you. First: I am plott…
Help Stata SE 16.1 | Structural equation modelingGood morning. I would like to get the same format of result as the picture (Result.PNG). My question…
Subscribe to:
Post Comments (Atom)
0 Response to Dropping observations of a variable
Post a Comment