I'm hoping to get a little help on an issue I'm having creating a so-called 'local of locals' in Stata for use in a foreach loop of regression specifications. I currently have a list of 6 global macros that each define a Base_ or Alt_ regression specification, with each of these locals comprised of 2-6 variables. I'm then looking to store each of these specification macros in a single global aka. Spec global that can then be used in a foreach loop that will allow me to run sequential regressions of my dependent variable on each of the Base_ or Alt_ locals stored within the Spec local. I would prefer to do all this with locals, but have been running in to trouble storing the individual locals within a single local.
My current code appears to be such that when I run the foreach loop intended to regress the dependent variable on each of the specifications stored within the Spec global, Stata runs a series of regressions of the dependent variable on each independent variable within each local, rather than on the set of independent variables stored within each global. For reference, I've attached the code below.
Code:
** 4.1 Load Panel Dataset for Analysis use "`pathdata'\2. DTA Files\Panel_GTI_foranalysis.dta", clear ** 4.2 Specify Panel Data xtset Year Country_id ** 4.3 Define Baseline and Alternative Specifications global Base ln_GDPpc global Base_2 ln_GDPpc ln_Population Unemployment_R global Alt_1_CivLib ln_GDPpc ln_Population Unemployment_R Low_CivLib Med_CivLib global Alt_1_PolFree ln_GDPpc ln_Population Unemployment_R Low_PolFree Med_PolFree global Alt_2_CivLib ln_GDPpc ln_Population Unemployment_R Low_CivLib Med_CivLib Dailycaloricsupplykcalperso global Alt_2_PolFree ln_GDPpc ln_Population Unemployment_R Low_CivLib Med_CivLib Dailycaloricsupplykcalperso global Alt_3_CivLib ln_GDPpc ln_Population Unemployment_R Low_CivLib Med_CivLib Dailycaloricsupplykcalperso global Alt_3_PolFree ln_GDPpc ln_Population Unemployment_R Low_CivLib Med_CivLib Dailycaloricsupplykcalperso Refugees_asylum global Specs $Base_2 $Alt_1_CivLib $Alt_1_PolFree $Alt_2_CivLib $Alt_2_PolFree $Alt_3_CivLib $Alt_3_PolFree ** 4.3 Regressions //** 4.3.1 Baseline Spec //xtreg ln_GTI $Base, vce(cluster Year) ** 4.3.2 Loop Through Local Specifications foreach Spec of global Specs { xtreg ln_GTI `Spec' }
All the best,
Scott
0 Response to Generating a local of locals for use in a foreach loop of regression specifications
Post a Comment