Hi, I would like to take the levels of a variable (string) in one file and use that list to loop through variables in another file. Particularly I want to do some variable transformations only to the variables in the list of that variable transformation.
I have loaded the dataset where I need to loop through variables (do the transformations), and using preserve and restore I create the locals with the levels of the vars there. however, when I want to call this locals some few lines later, it doesn't work.
I think the local is being created because I can see the different strings being quoted after the command creating the local, but then when calling it nothing happens. Should I call it differently if the content is a string? Or would it not work because I'm in the preserve/restore environment?
If there's any alternative could you please let me know?
Thanks a lot
use "${dta_path}/dataset_raw.dta", clear
This is the part of the code I have:
*generate a local with the vars to be transformed for each transformation
preserve
import excel using "${codes_path}\havercodes_list_test.xlsx", sheet("variable_transformation") firstrow clear
drop if var == ""
ds var, not
local transf `r(varlist)'
foreach t of local transf {
tostring(`t'), replace //to be able to replace by a string
replace `t' = var[_n] if `t' == "1" // to make a list of vars for that transf
levelsof `t', local(vars_`t') clean
}
restore
*3y average (avg_3y) (one of the vars in the previous files is called avg_3y so a local called vars_avg_3y should have been created
foreach v of local vars_avg_3y {
by country_code: egen `v'_3y = filter(`v'), lags(0/12) normalise
}
Related Posts with Local storing string content not working
this is a testDear all, I need to create a variable which identifies, for each individual, the following statuses:…
How to obtain ML (Cox-Snell)R2 after using seemly unrelated regression (sureg)Dear forum, I have a basic doubts of methodology for which many of you may know the answer. I am u…
Coefplot: sort coefficients from different modelsHi all, I've seen this question get asked a few times (e.g. here), but I have been unable to find a…
Why is the variable name result treated differently by the Stata 17 table command?Can anyone explain why the table command under Version 17 should treat the variable name "result" di…
Reverse causality in panel data with count outcomeI have panel data on several thousand individuals and I am trying to estimate a model to look at the…
Subscribe to:
Post Comments (Atom)
0 Response to Local storing string content not working
Post a Comment