Hi All
I have a dataset having two variables cards_hh and cards_other.. cards_hh is a multiple-choice question and A, B, and C are names of different cards and D is for the other type which needs to be specified in cards_other. I want to replace D in cards_hh if it presents with other cards (A, B, C), or say when cards_other is not blank.
I have tried
replace cards_hh=subinstr(cards_hh, "D", "",1) if cards_others!="" $ cards_hh!="D"
, but It replaces all D from top to i bottom,n cards_hh whereas I want to keep observation in cards_hh where only D is present (15 cases)
Please help
I tried another way, but failed.
if cards_hh!="D" {
replace cards_hh=subinstr(cards_hh, "D", "",1) if cards_others!=""
}
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 cards_hh str60 cards_others
"B" ""
"A" ""
"AC" ""
"C" ""
"AC" ""
"AC" ""
"A" ""
"A" ""
"AB" ""
"AB" ""
"AC" ""
"AC" ""
"AC" ""
"ABCD" ""
"ABC" ""
"AC" ""
"AC" ""
"A" ""
"AC" ""
"A" ""
"A" ""
"A" ""
"ACD" ""
"ABC" ""
"AC" ""
"ABC" ""
"D" "inke pass in cards me se koi card nhi bana hus he"
"ABC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ABC" ""
"AB" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ACD" ""
"ABD" ""
"ACD" ""
"ACD" ""
"ABCD" ""
"ABD" ""
"ABD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ABC" ""
"ACD" ""
"AD" ""
"ACD" ""
"ACD" ""
"D" "central government health schem"
"ACD" ""
"ABC" ""
"AC" ""
"AC" ""
"A" ""
"AC" ""
"ABD" ""
"ACD" ""
"AB" ""
"ACD" ""
"AC" ""
"AC" ""
"ABC" ""
"AC" ""
"ACD" ""
"ABC" ""
"AC" ""
"C" ""
"C" ""
"AC" ""
"C" ""
"ABC" ""
"C" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ABC" ""
"AC" ""
"A" ""
"AC" ""
end
I have a dataset having two variables cards_hh and cards_other.. cards_hh is a multiple-choice question and A, B, and C are names of different cards and D is for the other type which needs to be specified in cards_other. I want to replace D in cards_hh if it presents with other cards (A, B, C), or say when cards_other is not blank.
I have tried
replace cards_hh=subinstr(cards_hh, "D", "",1) if cards_others!="" $ cards_hh!="D"
, but It replaces all D from top to i bottom,n cards_hh whereas I want to keep observation in cards_hh where only D is present (15 cases)
Please help
I tried another way, but failed.
if cards_hh!="D" {
replace cards_hh=subinstr(cards_hh, "D", "",1) if cards_others!=""
}
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 cards_hh str60 cards_others
"B" ""
"A" ""
"AC" ""
"C" ""
"AC" ""
"AC" ""
"A" ""
"A" ""
"AB" ""
"AB" ""
"AC" ""
"AC" ""
"AC" ""
"ABCD" ""
"ABC" ""
"AC" ""
"AC" ""
"A" ""
"AC" ""
"A" ""
"A" ""
"A" ""
"ACD" ""
"ABC" ""
"AC" ""
"ABC" ""
"D" "inke pass in cards me se koi card nhi bana hus he"
"ABC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ABC" ""
"AB" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ACD" ""
"ABD" ""
"ACD" ""
"ACD" ""
"ABCD" ""
"ABD" ""
"ABD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ACD" ""
"ABC" ""
"ACD" ""
"AD" ""
"ACD" ""
"ACD" ""
"D" "central government health schem"
"ACD" ""
"ABC" ""
"AC" ""
"AC" ""
"A" ""
"AC" ""
"ABD" ""
"ACD" ""
"AB" ""
"ACD" ""
"AC" ""
"AC" ""
"ABC" ""
"AC" ""
"ACD" ""
"ABC" ""
"AC" ""
"C" ""
"C" ""
"AC" ""
"C" ""
"ABC" ""
"C" ""
"AC" ""
"AC" ""
"AC" ""
"AC" ""
"ABC" ""
"AC" ""
"A" ""
"AC" ""
end

Comment