Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: Event within dates
From
David Kantor <[email protected]>
To
[email protected]
Subject
Re: st: Event within dates
Date
Thu, 01 Dec 2011 18:22:57 -0500
Hi.
1: You didn't state what you did exactly.
2: I haven't tested the code; it's just a suggestion. But it looks legal to me.
3: Please see my second reply -- that starts "Oops". It offers a correction.
4: What I wrote was not complete. It was intended to sit in the
context in which you had set the value of the local N. I suspect that
that was the problem.
In that case, you need to precede the given code with...
local N=_N
But you can also skip that by using macro-expression evaluation:
forval i = 1/ `=_N' {
forval j = 1/ `=_N' {
etc. etc.
HTH
--David
At 05:34 PM 12/1/2011, you wrote:
Thanks for the approach. But I am sorry when I tried it I got an
error message invalid syntax.
----- Original Message -----
From: David Kantor <[email protected]>
To: [email protected]
Cc:
Sent: Thursday, 1 December 2011, 20:51
Subject: Re: st: Event within dates
The following might work. It is an attempt to fill in some features
that were needed in your method.
But it is somewhat brute-force in its approach. It does looping over
observations (doubly), which is rarely needed.
There is probably a much better way to do this (involving -by-, for
one), but this is all I can do at the moment.
HTH
--David
forval i = 1/ `N' {
forval j = 1/ `N' {
replace rs1=1 if drug[`i]==1 & id[`i']==id[`j'] &
inrange(date[`i'] - date[`j'],-56,56) in `i'
}
}
[...]
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/