Dear Statalist,

I got a problem with running a loop.
I give you my whole code, so you can see how variables/matrices are defined.
The problem is: forvalues i=......{ } gives me an error message with `i' invalid name.

I would highly appreciate your help/suggestions.

Best wishes and thank you very much in advance!

Nico


Code:
set more off 
preserve 
drop if aage>0 & aage<=16 
drop if STATR==2   

reg  lfp   edu pexp pexp2 pexp3 pexp4 i.year i.yuk  i.cohort uratem married fd  if  (age>=25 & age<65) & female==0 & im==1 & yuk<=60, robust   

matrix beta=e(b) // to display matrix values write `matrix list beta' 
predict yhat if e(sample)
su yhat if e(sample)
scalar ybar=r(mean)
scalar nobs=e(N)
scalar beta0=beta[1,109] //  _constant is at 109.
matrix yuk=beta[1,"0.yuk".."60.yuk"]   
tabulate yuk if e(sample), matcell(yukmeans) // this gives me the absolute frequencies in a matrix or vector
matrix yukmeans=yukmeans/nobs // now generate the relative frequencies 
matrix i1=yuk*yukmeans // this is a 1x1 matrix, I checked. 
scalar i1=trace(i1) //  single value of the matrix and define a scalar 
scalar i2=ybar-i1  
                

generate yhat3=0 in 1/61    

forvalues i=0(1)60 {                                             // here is where the error message comes up!!!!!!!!!!!!!! `i' invalid name
    local j = `i’+1
    local alpha = el(yuk,1,`i'.yuk) 
    replace yhat3= beta0 + `alpha'  in `j'     
}     
         

         
generate x=_n   in 1/45     
    
    
scatter yhat3  x   
restore