Hello everyone,
This might seem a very simplistic problem, but I am getting an error "varlist required" when I try to run a loop to clean variables with different names but with similar entry issues. I feel I have specified the varlist though. Here is the code below:
program define clean_var, rclass
version 13.1
syntax varlist
disp "Variable List: `varlist'"
foreach var in `varlist' {
disp "Looping through: `var'"
***** SUBSTR FIXES *****
replace `var' = trim(itrim(`var'))
replace `var' = subinstr(`var', char(10), "", .)
replace `var' = subinstr(`var', char(13), "", .)
***** CHARACTER FIXES *****
replace `var' = "" if `var' == "-"
replace `var' = "" if `var' == "`"
replace `var' = "" if `var' == ","
***** DATE FIXES ******
replace `var' = "1/2" if `var' == "02jan2003"
replace `var' = "1/2" if `var' == "02jan2003"
replace `var' = "1/2" if `var' == "02jan2019"
}
Any help would be really appreciated!
Thank you,
Ayon
Related Posts with Varlist required error
How to add label to bar graphDear all, I am trying to add country labels to my bar graph, but somehow I cannot figure out how to…
Two line frequency graph helpHello everyone. I've been trying to figure this out on my own but I haven't been very successful. I…
extract variable name when the observation has a highest value.dear listers, I would like to fill in the cell with a variable name showing the highest value in a …
Trade estimation using the PPML methodDear Joao, I am working on trade potential estimation between Morocco and it's principal commercial …
Merging two data filesNewbie here. I am trying to merge two files - one is a headteacher survey from 200 schools. The sec…
Subscribe to:
Post Comments (Atom)
0 Response to Varlist required error
Post a Comment