Dear Statalist,

I want to estimate using GMM predicted Y value for each year and each country in a panel dataset
I used the following code to loop it through each country and each year using xtabond2
Code:
program define Regression_GMM

xtset companyid year_
xtabond2 Y L.Y X1 X2 i.indstry , ///
 gmm(L.Y X1 X2, collapse) iv( i.indstry, ///
 equation(level))    ///
 two small  

if _rc==0 {
    predict yhat_GMM, xb
 
}
end

runby Regression_GMM, by(nation year_) verbose
But when I run this it gives me the message
HTML Code:
No observations.
       panel variable:  companyid (strongly balanced)
        time variable:  year_, 2001 to 2001
                delta:  1 unit
for all the year/country combinations

But when I run this manually for each country/year for selected country/year it runs with no problem
and give me an output
Code:
xtset companyid year_
xtabond2 Y L.Y X1 X2 i.indstry if nation == "country" & year == y1, ///
 gmm(L.Y X1 X2, collapse) iv( i.indstry, ///
 equation(level))    ///
 two small
Could you help me by mentioning:

1) How to run Y L.Y X1 X2 i.indstry regression with GMM/xtabond2
2) How to loop it through each country/year without an issue

Further, I asked this looping question in an earlier post and now I want to extend this to GMM/xtabond2

Previous Post:
https://www.statalist.org/forums/for...-panel-dataset