Dear All,
I have a variable that corresponds to different indicators from an OECD database. I would like to create as many variables as the number of levels of indicator2
for instance, I already created pct_millions with this
But since there are a lot of levels it's quite time consuming and "old -fashuoned" let's say, I was trying to looping over the levels of indicator2 to create the variables :
Blow an example of data and after that an example of the code I used, hope you can help.
But i get the following error foreach command may not result from a macro expansion interactively or in do files.
Hope I make myself clear and someone can help.
Thanks a lot,
Dalila
I have a variable that corresponds to different indicators from an OECD database. I would like to create as many variables as the number of levels of indicator2
for instance, I already created pct_millions with this
Code:
g pct_million = patents if indicator2 =="pct_million"
Blow an example of data and after that an example of the code I used, hope you can help.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str19 indicator2 float(pct_million pct_total) "pct_ict" . . "rd_exp_he" . . "pct_pharma" . . "pct_million" 79.3 . "pct_pharma" . . "pct_biotech" . . "pct_total" . 2032.3 "pct_medical" . . "rd_exp_he" . . "pct_million" 85.5 . end
Code:
levelsof indicator2, local(levels) . foreach l of local levels { . gen pct_`l' if varname == `l' . }
Hope I make myself clear and someone can help.
Thanks a lot,
Dalila
Comment