Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Event within dates

From   David Kantor <>
Subject   Re: st: Event within dates
Date   Thu, 01 Dec 2011 18:22:57 -0500


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.


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 <>
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.

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:

© Copyright 1996–2015 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index