Hi all
This is my first attempt at using dataex, hope it works.
I am having a problem with a simple if command, it doesn't seem to identify the observations that fit the condition.
Check this dataset sample:
The variable vasodilat is the original one I am trying to clean. It is a string variable containing several drugs being taken by each patient, separated by commas. I am trying to create 1/0 variables for each drug listed there.
I started by separating each individual drug in separate variables using the split command.
Then, starting with the case of the drug "aas", it should follow:
- If vasodilatad is missing, the future variable "aas" should be =.
- If vasodilatad has no drug listed which is =="aas", the future variable "aas" should be coded as 0.
- if vasodilatad has "aas" listed, the future variable "aas" should be =1.
I tried approaching it like this:
But as you can see in the following resulting dataset, I can't make it work, as there are observations with "aas" as one of the drugs listed, which was correctly separated in vasodil1/4, but aas is still =0.
I have reviewed the code over and over and can't find the issue, I am sure it must be pretty simple but I just can't see it.
Thank you...!
This is my first attempt at using dataex, hope it works.
I am having a problem with a simple if command, it doesn't seem to identify the observations that fit the condition.
Check this dataset sample:
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str45 vasodilatad "" "0" "0" "0" "0" "aas, amlodipina, pentoxifilina" "0" "0" "0" "amlodipina" "aas,pentoxifilina" "0" "0" "0" end
The variable vasodilat is the original one I am trying to clean. It is a string variable containing several drugs being taken by each patient, separated by commas. I am trying to create 1/0 variables for each drug listed there.
I started by separating each individual drug in separate variables using the split command.
Then, starting with the case of the drug "aas", it should follow:
- If vasodilatad is missing, the future variable "aas" should be =.
- If vasodilatad has no drug listed which is =="aas", the future variable "aas" should be coded as 0.
- if vasodilatad has "aas" listed, the future variable "aas" should be =1.
I tried approaching it like this:
Code:
split vasodilatad, parse(,) gen(vasodil) gen aas=. if vasodil1=="aas" | vasodil2=="aas" | vasodil3=="aas" | vasodil4=="aas" replace aas=1 else replace aas=0 replace aas=. if vasodilatad==""
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str45 vasodilatad str13 vasodil1 str14(vasodil2 vasodil3) str8 vasodil4 float aas "" "" "" "" "" . "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "aas, amlodipina, pentoxifilina" "aas" " amlodipina" " pentoxifilina" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "amlodipina" "amlodipina" "" "" "" 0 "aas,pentoxifilina" "aas" "pentoxifilina" "" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 "0" "0" "" "" "" 0 end
I have reviewed the code over and over and can't find the issue, I am sure it must be pretty simple but I just can't see it.
Thank you...!

Comment