Entering values into a matrix from a loop command

I have created a loop to generate a counter variable values that will then be entered into an OUTPUT matrix. Everything except for 1 line seems to be working. The line is here:

matrix OUTPUT[`i', `j']=counter
*STATA writes: counter not found. But then I write:
display counter
* STATA shows the value of counter, say 4:
*yet, if I just want to enter a number into the OUTPUT it works:
matrix OUTPUT[`i', `j']=4
*I.e. the program does not recognize the counter when I want to modify the matrix using its values. I have tried to use `counter' instaed of counter but an error is reported again.


Where is "counter" coming from? Can you show a bit of code prior to the matrix command? Are you trying to do this from within a do-file, from the command window, or from a combination of the two?