Hello, I am trying to make the following code work but it returns "var not found r(111);" I understand the problem is in the else statement. Any help will be appreciated, thank you, Alberto
*****
version 17
clear all
set more off
***************************************GEN TOY DATASET**************************
input str2(x1 x2 x3 x4)
1 4 6 Su
2 Su 7 9
3 Un 8 10
4 7 9 Un
5 5 10 12
end
destring _all, replace //note: x2 & x4 remain strings
****************************************PROGRAM*** ******************************
local cleanvar x1 x2 x3 x4
foreach var of local cleanvar {
capture confirm string variable `var'
if !_rc {
*here do nothing because numeric
}
else {
replace `var' =".a" if var == "Su"
replace `var' =".b" if var == "Un"
destring `var', replace
}
}
saveold try_tidy.dta, replace
Related Posts with Loop through string and numeric variables
Creating a variable with a data from another datasetI have two dataset. I need to fill (or generate) the variable Priceintargetpricedate in dataset one …
-ereturn repost, resize- displays "resize option not allowed"Dear Statalist. I am trying to add a 0 to my coefficient vector and variance matrix using -ereturn …
fixed effects helpI need to identify workers working in the same firm and same MSA. I have panel data. Y=a + b*X + fi…
Troubleshooting X11 Forwarding after an SSH tunnel to an EC2 InstanceI am doing an SSH tunnel to an AWS EC2 instance with the eventual goal of getting a working GUI of S…
Panel Data Autocorrelation and Estimator ChoiceI am trying to understand this paper by David McKenzie. One of the themes in the paper is how level …
Subscribe to:
Post Comments (Atom)
0 Response to Loop through string and numeric variables
Post a Comment