Hello, I am doing a lot of -foreach- statements, giving a variable a new name. An example:
Next I want to create an average by year, instead of having avg_real_"name", i would like to have only avg_"name", so I use the real values to do the calculations, but I want to have the nominal names with an avg_ prefix. I tried to do something like this:
But this gives an error, invalid syntax.
In $string I have "wage asset ...", after I ran the code I figured out that was obviously going to fail. Does anyone have a pointer or a hint to something that would do this? The goal is to create shorter/snipped names without much extra/manual work.
Code:
foreach x of varlist $nominal { capture gen real_`x' = `x'*deflator
Code:
foreach x of varlist $real { capture by year: egen subinstr(`x',$string,"avg",1) = mean(`x') }
In $string I have "wage asset ...", after I ran the code I figured out that was obviously going to fail. Does anyone have a pointer or a hint to something that would do this? The goal is to create shorter/snipped names without much extra/manual work.
Comment