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
Drop rows that are empty in all variablesHi Statalist I have a question about trying to drop those rows that are empty in all the variables …
mcp error "There was a problem executing -margins-."Dear colleagues, my first post here so apologies if I'm doing it wrong. I always use Royston's mcp …
SUR-like technique for same outcome but multiple predictorsHello, I am running a series of multinomial logistic regressions that use the same outcome variable…
Hypothetical default rateDear Statalist, I have a dataset containing loans which are followed through time. I am running a l…
Check if coefficient from two different reghdfe regressions is the sameHi all, I am using Stata 15 on Windows. I have data on houses and study the effect of mixed use on…
Subscribe to:
Post Comments (Atom)
0 Response to Local storing string content not working
Post a Comment