Sorry, but I think we're deadlocked. I don't understand your problem
well enough to solve it, and there's a limit to how much time I can
spend on a problem whose formulation keeps changing. And you don't know
enough Stata to solve it by yourself. In fact, I am not yet convinced
that you need a program, as compared with a do file.
You can nest -forvalues- calls.
Otherwise aren't there people at your institution who can help?
Nick
[email protected]
Ilona Carneiro
Thanks, Nick. Apologies for changing the variable names - I was
originally trying to present a generalised code as in my larger ado
file, but as I get more tired with this am reverting to my basic
variable names to avoid more programming errors! pin is the identifier
- previously `id', anmal is the treatment variable - previously `tx'
and mal0 is the `case' variable.
I have to admit that I didn't understand your suggestion about
tagging. Your suggestion 2 involved first "looping over individuals",
but that is the bit I can't seem to do. I originally tried to write
the programme without it being byable, but couldn't work out how to
get it to loop over individuals as the 'forvalues' command can't be
combined with `by'. I was trying to adapt the panelthin code, and the
point is taken about display of scalars - I still can't seem to get
this to work for me, and I think the code is not appropriate for what
I need.
I need to run forvalues { } separately for each individual, where
forvalues denotes the sequential observations for that individual. How
do I do this?
Also tried the programme as byable(onecall), but this didn't work
either
On 1 Mar 2009, at 19:08, Nick Cox wrote:
> Of my suggestions,
>
> 3. -panelthin- and 0. -tsspell- do assume -tsset- data; that's
> implied by their purpose and in each case documented in their help
> files. But I didn't suggest that either would necessarily solve your
> problem, just that they might give you some ideas.
>
> 1. and 2. don't presuppose -tsset- data.
>
> In your code, you combine two quite different and contradictory
> strategies, (1) writing a -byable- program and (2) building in the
> identifier and time structure of your data. You are also writing a -
> recall- program when I suspect that -onecall- is closer to your
> problem. Regardless of that detail I'd go for (2).
>
> -pin- appears here and is not explained. I guess that is equivalent
> to the -id- of earlier postings. A more general point is that others
> have little hope of understanding clearly anything that you do not
> explain. In particular, other variables -anmal- and -mal0- appear
> here which do not seem to have been mentioned in your earlier
> postings.
>
> Within no variables specified and no scope for -if- and -in-
> conditions, your variable -touse- will always be 1. Your code can I
> think be simplified without loss to
>
> program ilona, sortpreserve
> quietly {
> tempvar T t
> bysort pin (start): gen `t' = _n
> by pin : gen `T' = _N
> sum `T', meanonly
> local tmax = r(max)
> drop `T'
> replace lagend = (end + 19 + 1) if (anmal > 0 & anmal < .)
> forvalues i = 1(1)`tmax' {
> drop if end < lagend[`i'-1] & lagend[`i'-1] < . &
`t'==`i' & `i'!=1
> replace lagend = (end + 21 + 1) if (mal0 > 0 & mal0 < .)
&
> lagend==. & `i'<`tmax'
> }
> }
> end
>
> -- but I have no idea whether this is progress or not.
*
* 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/