Hello,

I am a PhD student and I have not been using Stata that long (about a year) so my apologies if the answer to this question is obvious. I have been looking for an answer for why this is happening for several days but have not had any success on my own.

Recently, my faculty advisor recommended that I look at some national data from the National Survey on Drug Use and Health (NSDUH) as part of my dissertation work. He is out of the country and this is quite time sensitive. After completing my analyses, I was going through the data documentation regarding estimate suppression for potentially unreliable estimates. They include code for SUDAAN, Stata and SAS. I tried the suggested Stata code (see below) and continually get the error message 'counter invalid name' (see bolded part of code where things are going wrong for me).

Here is a link to the NSDUH documentation (see page 71): https://www.samhsa.gov/data/sites/de...erence2015.pdf

Here is the code provided producing the error message 'counter' invalid name:

use using “.\\dataname.dta”, clear /*Ensure all variables are lower case*/
rename *, lower /*ID Nesting variables (VESTR and VEREP) and weight variable (ANALWT - standard single-year, person-level analysis weight*/

svyset verep [pw=analwt], strata(vestr) dof(750)

gen total_out=.
gen setotal=.
gen mean_out=.
gen semean=.
gen nsum=.
gen wsum=.
gen deffmean=.

/* Estimated means of past month alcohol use by year and gender*/
/*Year variable, where 2013=1 & 2014=2*/
/*Gender variable, where male=1 & female=2*/

svy: mean alcmon, over(year irsex)

matrix M=e(b) /*Store mean estimates in matrix M*/
matrix S=e(V) /*Store variances in matrix S*/
matrix N=e(_N) /*Store sample size in matrix N*/
matrix W=e(_N_subp) /*Store weighted sample size in matrix W*/
estat effects, deff srssubpop /*Obtain design effect*/
matrix D=e(deff) /*Store design effect in matrix D*/

/*Extract values stored in the M, S, N, W, and D matrices defined above to the mean_out, semean, nsum, wsum, and deffmean variables. The loop ensures that the appropriate values are extracted for each value of year and gender.*/

local counter=1
forvalues i=1/2 { /*number of years*/
forvalues j=1/2 { /* number of gender categories*/
replace mean_out=(M[1,`counter’]) if year==`i’ & irsex==`j’
replace semean=(sqrt(S[`counter’,`counter’])) if year==`i’ & irsex==`j’
replace nsum=(N[1,`counter’]) if year==`i’ & irsex==`j’
replace wsum=(W[1,`counter’]) if year==`i’ & irsex==`j’
replace deffmean=(D[1,`counter’]) if year==`i’ & irsex==`j’
local counter=`counter’+1
}
}


Thank you in advance for any help or suggestions you can provide.