Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Program and syntax error "weights not allowed"


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Program and syntax error "weights not allowed"
Date   Thu, 31 Aug 2006 16:28:18 +0900

Alvine Bissery wrote:

I've a problem with this program.
It seems not possible to replace a value in tata vector.
Could someone explain me ?
How can I do ?

gen tata=0
forvalues i=1/34290 {
local J=nb_exam[`i']
forvalues j=2/`J' {
replace tata[`i']=1 if (date_presc1[`i']!=date_presc`j'[`i'])
}
}

weights not allowed

--------------------------------------------------------------------------------

Stata won't let you put tata[`i'] on the left-hand side of the equals sign.

So, change the line

replace tata[`i']=1 if (date_presc1[`i']!=date_presc`j'[`i'])

to something like

replace tata = 1 if (date_presc1 != date_presc`j') in `i'
or
replace tata = 1 if (date_presc1 != date_presc`j') & _n == `i'

Joseph Coveney

P.S. I cannot follow what it is that you're trying to do, but it seems as if
there ought to be a simpler way.  You're looping over both observations and
reshaped wide variables (or something), which isn't the optimum approach
with Stata in most cases.  I recommend exploring whether there is some way
to "vectorize" the solution, using -generate- or -egen-, for example.


*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index