I hope you are doing well.
I exported a document from Excel into Stata.
One of the column was in % in Excel. When exporting it on Stata, it has now a mix with % and decimal (0.33 for 33%).
I am trying to convert each % to a decimal number.
Code:
stake 1 66% 33% .67 .33 .33 .67
Code:
gen x = strpos(stake, "%") > 0 gen new_stake = stake if x == 1 replace new_stake = subinstr(new_stake, "%", "",.) encode new_stake, generate(new_stake2) replace new_stake2 = (new_stake2/100) destring new_stake2, replace replace stake = "." if x == 1 encode stake, generate(stake2) replace stake2 = new_stake2 if stake == .
Is there any way to do it with less code or change directly the percentage in my stake column directly?
Thank you very much !
0 Response to If statement with string
Post a Comment