I am trying to drop entire records of individuals from this set if they had an opportunistic infection (OI) within a period of time.
I need a second opinion to assess if my code is doing the right thing.
Please note that I did a data dump because I feel randomtag will not do justice to me, in trying to select a representative sample to replicate the problem.
replace OI= "" if OI =="NONE"
replace OI= "" if OI =="ULCERS"
encode OI, gen(OI_)
la li OI_
recode OI_ (1/66=.) (else=1), gen(OIs_recoded)
distinct patient_id
bysort patient_id (OI_Date OIs_recoded) : drop if inrange(OI_Date , td(30jul2014), td(30jan2015)) & missing(OIs_recoded [1]) | missing(OIs_recoded [_N])
distinct patient_id
PS: Attached is the data file because I feel the dataex version is not representative enough
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input long patient_id int OI_Date str69 OI 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 19681 "NONE" 52 . "" 52 19563 "OTHER NON-CODED" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 52 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" 53 . "" end format %tdnn/dd/CCYY OI_Date
0 Response to Dropping all Observations in a Longitudinal Data Set if Two Conditions are met.
Post a Comment