Dear Statalist users
I have a dataset which has a string variable in three parts, by convention, separated by a hyphen: e.g. 12345-2020-0001
The last part is designed to run serially from 0001 to 9999. However, the dataset has observations with extra zeros like -00001or -00045 instead of -0001 and -0045 respectively.
I would like to remove one of the zeros in -00001 and -00045
I have tried the command below without success
local var1 "stringvar"
foreach r of local var1 {
replace `r' =subinstr(`r',"`-000??'","`-00??'",.)
}
I am using Stata SE version 16.1 for Mac
Can someone help me with a solution.
Thank you
Mutugi Muriithi
Related Posts with How to remove an extra digit/character from a string variable
svy: logit goodness-of-fit tests (subpopulation)Hi, how can I use stat gof if I need to keep subpop to keep the correct estimation of variances and …
generate retirement ageHey all, I am using panel data and have a full population dataset. I can observe an individuel over…
Generating an indicator variable to denote the highest value from a set of variables in an observationI am working with a dataset from a poll of registered voters. For each observation (one voter), resp…
Turning three variables into one based on year. Code included Code: * Example generated by -dataex-. For more info, type help dataex clear input double hhid int …
Moran scatter plot for different periodsHi, I have panel data from 1990-2017. I can use spatwmat command to create a weight matrix. And spa…
Subscribe to:
Post Comments (Atom)
0 Response to How to remove an extra digit/character from a string variable
Post a Comment