I am a beginner stata user and new to this post. I found this forum was extremely helpful when I google search for stata help.
I have 5 dependent variables and I need to run same regressions for each of the dependent variables. For each dependent variable, I will run three sets of regressions and the only difference between the three sets of regression was one set of interaction terms were using different variables. instead of running one loop for 5 dependent variables three times for each of the three interaction terms and control variables, I think a loop for 5 dependent variables and a within loop for the three interaction terms can make it easier.
Here are my codes:
local ppost t_state##ib2.p_c ---i used this to create a local variable for my interaction terms, which may be wrong
local postdum t_state##ib0.post
local state st##ib2.p_c
local pv `ppost' `postdum' `state'
foreach v of varlist b2 b4 b8 b2 b16{
foreach p of local pv{
xi:svy: reg `v' `p' $charm if r_`v'==1 & family==0
est sto nom_`v'`p'
}
}
the model run only for the first variable and the first interaction terms, which is t_state##ib2.p_c with an error message:
# invalid name
# invalid name
ib2.p_c invalid name
r(7);
I suspect that it was because I did wrong when define local for the interaction terms. I tested the following
display `pv'
invalid matrix stripe;
t_state##ib2.p_c
r(198);
Thank you very much for the help!
Related Posts with try to do a loop within a loop
Transpose (rotating) data by group (variable)Dear all, I need to transpose my dataset so that I can calculate the pairwise correlation matrix fo…
Creating treatment and control groups for regression modelThis is a continuation of my previous post Grouping values within a variable that Clyde Schechter ha…
Saving fixed effects after GLM estimationHi All, My dataset resembles the following: Code: * Example generated by -dataex-. To install: ss…
Filling a time-invariant dummy variable down for new years in panel data after expanding a datasetHi I am looking to fill in missing observations for a dummy variable for firms (which each have an …
Latent class analysis (LCA) plugin - assertion is false -errorHello, I've been trying to use the LCA plugin from Penn State for my analysis using Stata/IC. I succ…
Subscribe to:
Post Comments (Atom)
0 Response to try to do a loop within a loop
Post a Comment