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
Multilevel model: about the decision of levelsHi Everybody, I'm using a panel data (from year 2013 to 2020) about firms' R&D, sales, region of…
gen id = _nDear All, Consider the following case, Code: clear set seed 12345 set obs 20000000 gen id = _n We c…
Problems with FE in capital structure studyHello all. For my thesis I'm researching the capital structure in the UK and France. More specifical…
Graph svy total with confidence intervalsHi Is there any way to make a graph of a estimate total with 95% confidence intervals of a variable …
Generating and exporting summary table to ExcelHello, I am trying to produce a table that offers some summary statistics (Ns and %s, and averages, …
Subscribe to:
Post Comments (Atom)
0 Response to How to remove an extra digit/character from a string variable
Post a Comment