I have a programming problem when setting up a macro and would like to ask your help. Let's assume I have a macro with a set up variables:
Code:
local vlist var1 var2 var3 var4
Code:
local list var1#var1 var2#var2 var3#var3 var4#var4 // 2nd order poly var1#var1#var1 var2#var2#var2 var3#var3#var3 var4#var4#var4 // 3rd order poly var1#var2 var1#var3 var1#var4 var2#var3 var2#var4 var3#var4 // two-way inter var1#var2#var3 var1#var2#var4 var2#var3#var4 var1#var3#var4 // three-way inter
Code:
local vlist "var1 var2 var3 var4"
local count: word count `vlist'
* create 2nd & 3rd order polynomials
local series1 = 1
local series2 = 2
foreach var in `vlist' {
local order1 : di _dup(`series1') "#`var'"
local poly1 "`poly1' `var'`order1'"
local order2 : di _dup(`series2') "#`var'"
local poly2 "`poly2' `var'`order2'"
}
* create all possible interactions
forval i = 1/`count' {
gettoken `i' vlist : vlist
foreach j of local vlist {
local inter "`inter' ``i''#`j'"
}
}
di "POLYNOMIALS:"
di "`poly1' `poly2'"
di "INTERACTIONS"
di "`inter'"
* the macro of interest:
global ilist `poly1' `poly2' `inter'Could someone help me creating this macro?
Thank you very much in advance for your time and your interest in my problem.
Wishes,
Eva
P.S. I use Stata 16 version.
0 Response to Create a macro of all polynomials and all possible interactions between variables that are set in one macro.
Post a Comment