Hi there,

My panel data set includes 389 companies and 51 quarter years. I am trying to regress my regression for each company and to save coefficients. If I regress regression as manual, Stata produces coefficients. For example;

Code:
// for company 1 :

nlsur (l_q=ln({A})+({s}/(1-{s}))*(ln(({a1}*K^(({s}-1)/{s}))+((1-{a1})*((exp({d}))*L))^(({s}-1)/{s})))) (l_KY=ln({a1}/(1+{mu}))+(({s}-1)/{s})*(ln(Y/K)-ln({A}))) (l_LY=ln((1-{a1})/(1+{mu}))+(({s}-1)/{s})*(ln(Y/L)-ln({A})-{d})), initial(i), if id==1

// for company 2 :

nlsur (l_q=ln({A})+({s}/(1-{s}))*(ln(({a1}*K^(({s}-1)/{s}))+((1-{a1})*((exp({d}))*L))^(({s}-1)/{s})))) (l_KY=ln({a1}/(1+{mu}))+(({s}-1)/{s})*(ln(Y/K)-ln({A}))) (l_LY=ln((1-{a1})/(1+{mu}))+(({s}-1)/{s})*(ln(Y/L)-ln({A})-{d})), initial(i), if id==2
where id is company id and id =(1,2,....,389)

However, I do not want to do that for 389 companies. I want to use "foreach" or "forvalues" loop commands. So I am trying to run this code:

Code:
gen coeff= . // empty variable for coefficient

levelsof id, local(levels) // id is company id
foreach i of local levels{
    
    nlsur (l_q=ln({A})+({s}/(1-{s}))*(ln(({a1}*K^(({s}-1)/{s}))+((1-{a1})*((exp({d}))*L))^(({s}-1)/{s})))) (l_KY=ln({a1}/(1+{mu}))+(({s}-1)/{s})*(ln(Y/K)-ln({A}))) (l_LY=ln((1-{a1})/(1+{mu}))+(({s}-1)/{s})*(ln(Y/L)-ln({A})-{d})), initial(i), if id=='i'
    
    replace coeff= _b[A] if id=='i'
}
But I received "i invalid name" error.

What is my mistake? How can I solve this problem? Can I generate a result variable like that:
Firm ID A a1 s mu
1 .. .. .. ..
2 .. .. .. ..
Thank you for your interest.


Error:


Array