Hi,
I have a set of 24 variables reporting information for some treatments for a sample of patients. Both patient id and treatment variables are string. I am trying to figure out how I could keep only some specific values from those string treatment variables. The rest of treatments contained in those variables, I would be keen to delete or recode to missing. I would be interested in deleting the rest or recoding into missing.
The problem I envisage is that some times the treatment I am interested in is duplicated in other treatment variables (over the 24 different variables to reflect treatments). I would be interested in keeping only a set of treatments the tI am interested in.
So far, the code I have tried is as follows:
* Define a macro to ascertain the range of treatments of interest
local i of A B C D E F G F H
* Run the loop over the patient id and treatment variables
foreach num in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 {
bys id_patient: egen disease="." if treatment_`num'!="`i'"
replace disease="ì'" if treatment_`num'=="ì'"
drop if disease=="."
}
Kind regards,
Alberto
Related Posts with keeping only some values from string variables
Problem - Use 2 datasets in one do file (single run)Hi all ! I need help on stata I am trying to create one do file in Stata (mandatory) using 2 diff…
Filtering quality variablesI am having s panel data on macro variables for 72 countries (I. e. ;gdp, inflation etc) and a conti…
Panel Regression with a Moderator Variable*Please forgive my lack of Stata/Statistics knowledge or basic questions, I'm fairly new to Stata an…
datetime 2012-04-24 08:00:01Hello, I am trying to import "2012-04-24 08:00:01" as a datetime, but it shows as "2012-04-24 07:59…
Calculate number of "common friends" in the past five yearsDear fellow Statalisters, For a large panel data set on alliances, I want to calculate the number o…
Subscribe to:
Post Comments (Atom)
0 Response to keeping only some values from string variables
Post a Comment