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
gologit2 suddenly having problems in Stata 15I have sent this problem to Stata tech support. I will be amazed if anyone on the list can help me b…
Change date variable to one stata can readHello Statalist, I've a question regarding my dataset. I want to extract the year and month separat…
R squared - Negative binomialHello everyone! I am currently performing some negative binomial regressions (xtnreg) with my pan…
Checking for Hetro in Longitudinal (Panel) DataGood Day, I am trying to check for hetro issue in my longitudinal data where the N is large and P is…
time variable mistakeHi, I have a balanced panel data set with data, for each cross-section, up until 2016 (i=10, t=147)…
Subscribe to:
Post Comments (Atom)
0 Response to How to remove an extra digit/character from a string variable
Post a Comment