Hello,
I have a dataset with ~881k observations and 621 variables that I'm just beginning to clean.
The vast majority of the data is numeric but I have a chunk of 87 variables that are stored as string and contain either "yes", "no" or ".". I can encode them in a loop using the below but this also encodes "." as a number.
I have read the help files on encode and searched several posts and articles but I'm beginning to think it either isn't possible and I need to approach it another way or i'm missing something plainly obvious that I just cannot see?
foreach v of varlist var1-var87{
encode `v', generate (new`v')
drop `v'
rename new`v' `v'
}
Any advice would be appreciated.
I'm using STATA 16 SE
Aidan
Related Posts with Loop Encode but ignore "."
Fixed effects (individual and time), interacting FEs, and Time TrendsHi everyone! I have panel data of the form: Country Continent Year agprod drought ABW LAC 1972…
Merge datasets based on a range of a variableHi Statalist, This is my first post but I have found this forum invaluable in the past. Hopefully …
Mixed effect modelHi Stata experts, I have a longitudinal dataset with outcome recorded at 8 timepoints and exposure …
Help with rangestat calculating moving average results in all missing valuesHello I am trying to calculate the rolling average of the past 36 months (periods) and when I run th…
How do I keep the lowest numeric value for a variable on an annual basis over time?I have a focused question. I am working in long format. One of my variables is called “new_diff_days…
Subscribe to:
Post Comments (Atom)
0 Response to Loop Encode but ignore "."
Post a Comment