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

Re: st: AW: Problem looping over spells for an individual

From   Ilona Carneiro <>
Subject   Re: st: AW: Problem looping over spells for an individual
Date   Wed, 25 Feb 2009 17:51:09 +0100

HI Martin

I tried checking this before, but I didn't know how to interpret it.

With tr: byid I get:
 if __000000 {

But I don't know what that means?


On 25 Feb 2009, at 17:39, Martin Weiss wrote:


Are you sure the line

if `touse' {

does what you want it to? -set trace on- or indeed use the recently
announced -ssc d tr-  and report what happens...


-----Ursprüngliche Nachricht-----
[] Im Auftrag von Ilona Carneiro
Gesendet: Mittwoch, 25. Februar 2009 17:24
Betreff: st: Problem looping over spells for an individual

Hello all

I am trying to write a programme that will run a command sequentially
for observations of an individual. For each individual I have multiple
spells and multiple failures. However, the twist is that I also need
to exclude a period of time at risk after each treatment (prophylaxis)
and after each failure (to prevent double-counting of failures that
may actually be the same episode). I managed to do this without any
problem for the treatment, but if an episode is disqualified (by a
prior treatment or episode) I don't want it to disqualify a subsequent
episode. Therefore I need to run the code sequentially for each spell
of an individual, but using the marksample touse code to run it "by"
individual doesn't seem to be working - the "forvalues" seems to
always interpret _N as the last observation in the whole dataset, not
the last observation for each individual.

I have the following code:

		program define byid, byable(recall, noheader)
		marksample touse
		sort `id' `start'
		if `touse' {
		forvalues i = 1(1)`=_N' {
		replace lagend = (`end' + `lag') if ((`tx' > 0 & `tx' < .) |
0 & `case' < .))
		drop if lagend[`i'-1]>`end' & `id'[`i'-1]==`id'
		gen lagend=. 	
		qui by id: byid

but I get the error:
2nd by group not found

And the programme isn't doing what I need it to.

Any ideas?


*   For searches and help try:

*   For searches and help try:

*   For searches and help try:

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