Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: Event within dates

From   David Kpento <>
To   "" <>
Subject   Re: st: Event within dates
Date   Fri, 2 Dec 2011 08:20:42 +0000 (GMT)

I am sorry the new approach did not work.

Thanks for any help.

David Kpento

PhD Student,

University of Ghana


----- Original Message -----
From: David Kantor <>
Sent: Thursday, 1 December 2011, 23:22
Subject: Re: st: Event within dates


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:

*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index