Hi,

In the following dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(grid coeff1) float(grid_1 grid_2 grid_3 f0)
 .4486396262520715  .0005256978029485812  .4486396  .2012775 .09030107 0
.44865590670032207 -.0008528920278404954  .4486559 .20129213  .0903109 0
.44867218714857265  .0003351585090252788  .4486722 .20130673 .09032073 0
 .4486884675968232 .00012919439508951027  .4486885 .20132133 .09033056 0
.44870474804507376                     . .44870475 .20133595  .0903404 0
.44872102849332435                     .   .448721 .20135055 .09035023 0
.44873730894157493                     .  .4487373 .20136517 .09036007 0
 .4487535893898255                     .  .4487536  .2013798  .0903699 0
.44876986983807604                     .  .4487699  .2013944 .09037974 0
 .4487861502863266                     .  .4487861   .201409 .09038957 0
 .4488024307345772                     .  .4488024  .2014236 .09039941 0
 .4488187111828278                     .  .4488187 .20143823 .09040925 0
end
I would like to update each value of f0 with the dot product of "coeff1" and the each row of grid_1, grid_2, and grid_3. Coeffi1 is contains the regression coefficients from estimating a OLS model. For example, I would like f0[1] = .0005257 * .4486396 + (-.00085289) * .2012775 + .00033516 * .0903011 + .00012919. The last value of "coeff1" is the constant from OLS model.

My attempt at this is the following:

Code:
        summ grid
        local N1 = r(N)
        di `N1'
        summ coeff1
        local N2 = r(N)
        di `N2'-1
        forvalues k = 1/`N1' {
            forvalues q = 1/(`N2'-1) {
                replace f0 = f0[`k'] + coeff1[`q'] * grid_`q'[`k'] in `k'
            }
            replace f0 = f0[`k'] + coeff1[`N2'] in `k'
        }
The for loop gives me the "invalid syntax" error message. I am not sure where the problem is. Does anyone know where I messed up?