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
Need Time-Stratified Case-Crossover Study Help...Hello there! I have hit a bit of a wall with my time-stratified case-crossover study for my disserta…
A function for a numberHi, I am writing a loop that looks like this foreach code of numlist 1/202{ forvalues i=1940/2020{ …
Export covariance matrix to ExcelHi, I would like to export the following covariance matrix to excel: Code: * Example generated by…
Reshape long 1 row dataset with no identifierHi, I am trying to reshape long the following dataset: Code: * Example generated by -dataex-. To i…
Calculate export times using custom data HTML Code: clear input str10 company_name str3 country int year "3Mcompany" "USA" 2002 "3Mcompany"…
Subscribe to:
Post Comments (Atom)
0 Response to Dropping observations of a variable
Post a Comment