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
Is my Xtdpdgmm syntax correct?xtdpd L(0/2).n L(0/1).(w k ys) year yr1980-yr1984, dgmmiv(n w k ys) div(year yr1980-yr1984) twostep …
Create a variable that has only one value per categoryI have data on automobile collisions in a particular region and, among other things, have data on th…
Monthly labor force status stored as a string variableHello, I am working with a data set which storing monthly labour force status during the survey ref…
Checking cointegration among all possible pairs in a datasetDear All., I have the following dataset referring to daily observations for a bunch of US stocks: …
Event study/ DID/ Individual FE/ Time&County FEHi, I am new to Stata and in need of an advice on how to translate my model specification into code…
Subscribe to:
Post Comments (Atom)
0 Response to Varlist required error
Post a Comment