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
How to graph two variables and the growth rate of a variableHi, I have a problema that I just cant resolve. I have a dataset with more than 120.000 obs and 66…
calculate beta using rangestatHi everyone, I want to calculate the beta of the stock market using the CRSP data. The RANGESTAT is,…
Cumulative ReturnsI want to calculate the cumulative return by firm between the financial statements announcement date…
How to handle the missing values generated by tssmooth exponential in unbalanced panel dataDear all, I have an unbalanced panel dataset. Panel variable is firm_id and time variable is year. …
define a dummyDear all, I am asked this question. The data set is Code: * Example generated by -dataex-. To inst…
Subscribe to:
Post Comments (Atom)
0 Response to Loop through string and numeric variables
Post a Comment