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
Correlation Matrix and VIFHello everyone, sorry to bother you all. I got some question about multicollinearity. Since my mode…
xtreg vs xtsccHi, I am trying to estimate the impact of directors' remuneration on firm performance. My unbalance…
browsing from a listGoodmorning, I often encounter a very basic problem (as a beginner) and am wondering if there is a …
Optimal Lag for Breusch–Godfrey TestDear all, I have a question about the optimal number of lags for the Breusch-Godfrey Test. I have d…
Creating a new variable in paneldataDear Stata users, I am new to using STATA and I have searche dthe forum but could not find an answe…
Subscribe to:
Post Comments (Atom)
0 Response to Varlist required error
Post a Comment