Dear Satalist
I am using stata 12, abd I am trying to convert the variable V5_MOTIFS that takes the value "Je ne sais pas" , Inexistant" , "A renforcer" , "Trop léger" " Suffisant" to a categorical variable
More precisely I want this variable to take te value of
- "0 "when it takes the value of "Je ne sais pas
- "1" when it takes the value of "Inexistant"
- "2" when it takes the value of "Trop léger"
- "3" when it takes the value if "A renforcer"
- "4" when it takes the value of "Suffisant"
To do that I proceeded in several steps. First I turned my variable from a string to a numeric variable using the command :
encode V5_MOTIFS , gen( V5_MOTIFS_ )
Then I replace the string value by a numeric value using the commands
replace V5_MOTIFS_=0 if V5_MOTIFS=="Je ne sais pas"
replace V5_MOTIFS_=1 if V5_MOTIFS=="Inexistant"
replace V5_MOTIFS_=2 if V5_MOTIFS=="Trop léger"
replace V5_MOTIFS_=3 if V5_MOTIFS=="A renforcer"
replace V5_MOTIFS_=4 if V5_MOTIFS=="Suffisant"
However I does not seem to work and remplace the value by the good value
For exemple when I use
replace V5_MOTIFS_=1 if V5_MOTIFS=="Inexistant"
The varaibles V5_MOTIFS_ get the value "." attributed" instead of "1"
wHEN i USE
replace V5_MOTIFS_=2 if V5_MOTIFS=="Trop léger"
The variable V5_MOTIFS_ gets the value A renforcer instead of 2
Here an example of my datastets. I only kept one variable V5_MOTIFS but I have the same issue with others
Thanks a lot for your time,
Best regards,
Najiba
I am using stata 12, abd I am trying to convert the variable V5_MOTIFS that takes the value "Je ne sais pas" , Inexistant" , "A renforcer" , "Trop léger" " Suffisant" to a categorical variable
More precisely I want this variable to take te value of
- "0 "when it takes the value of "Je ne sais pas
- "1" when it takes the value of "Inexistant"
- "2" when it takes the value of "Trop léger"
- "3" when it takes the value if "A renforcer"
- "4" when it takes the value of "Suffisant"
To do that I proceeded in several steps. First I turned my variable from a string to a numeric variable using the command :
encode V5_MOTIFS , gen( V5_MOTIFS_ )
Then I replace the string value by a numeric value using the commands
replace V5_MOTIFS_=0 if V5_MOTIFS=="Je ne sais pas"
replace V5_MOTIFS_=1 if V5_MOTIFS=="Inexistant"
replace V5_MOTIFS_=2 if V5_MOTIFS=="Trop léger"
replace V5_MOTIFS_=3 if V5_MOTIFS=="A renforcer"
replace V5_MOTIFS_=4 if V5_MOTIFS=="Suffisant"
However I does not seem to work and remplace the value by the good value
For exemple when I use
replace V5_MOTIFS_=1 if V5_MOTIFS=="Inexistant"
The varaibles V5_MOTIFS_ get the value "." attributed" instead of "1"
wHEN i USE
replace V5_MOTIFS_=2 if V5_MOTIFS=="Trop léger"
The variable V5_MOTIFS_ gets the value A renforcer instead of 2
Here an example of my datastets. I only kept one variable V5_MOTIFS but I have the same issue with others
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str14 V5_MOTIFS "." "." "." "A renforcer" "." "Suffisant" "." "Trop léger" "Suffisant" "A renforcer" "." "Suffisant" "Trop léger" "Trop léger" "A renforcer" "." "Suffisant" "A renforcer" "." "A renforcer" "." "Suffisant" "A renforcer" "." "A renforcer" "Trop léger" "A renforcer" "Inexistant" "Suffisant" "." "." "A renforcer" "Trop léger" "Trop léger" "A renforcer" "Trop léger" "A renforcer" "." "A renforcer" "A renforcer" "." "A renforcer" "A renforcer" "Trop léger" "." "Inexistant" "." "." "." "." "A renforcer" "Trop léger" "." "Trop léger" "A renforcer" "Trop léger" "Trop léger" "Suffisant" "." "." "Trop léger" "." "Trop léger" "." "." "A renforcer" "Suffisant" "A renforcer" "." "Suffisant" "Suffisant" "Je ne sais pas" "Je ne sais pas" "." "A renforcer" "A renforcer" "." "Suffisant" "." "Trop léger" "A renforcer" "Trop léger" "A renforcer" "Trop léger" "Suffisant" "Suffisant" "." "." "Suffisant" "Trop léger" "A renforcer" "Trop léger" "Suffisant" "." "." "Trop léger" "Suffisant" "Trop léger" "A renforcer" "Trop léger" end
Best regards,
Najiba
Comment