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
Generating residuals with miHi all, On p. 296 of the Stata 16 MI manual, the following is stated: The MI predictions shoul…
F-statistics so high.Hi. I'm PhD student. I have problem to analyze my result. Can i know, why F-statistics is so big. It…
Regression Command for pooled DataHi.. I have four countries cross section data in my sample. i regressed separate regression for each…
Table CreationHey Statalists, I have data with variable named district, hospital name and total number of cases ha…
Help Reshaping/Merging dataDear all, I am using Stata 16, on mac. Here is snapshot of a piece of my dataset. I have collected d…
Subscribe to:
Post Comments (Atom)
0 Response to Loop through string and numeric variables
Post a Comment