Statalist


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

st: RE: AW: RE: AW: RE: AW: irecode problem


From   "Kieran McCaul" <kamccaul@meddent.uwa.edu.au>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: AW: RE: AW: RE: AW: irecode problem
Date   Fri, 6 Mar 2009 06:58:11 +0900

It's running now, Martin.
It's part of a program to simulate a survival dataset with proportional hazards.  At the moment I've got it set to noisily display the output from each -stcox-, so when the first one comes up, I should know if it's working ok.  

Thanks again,
Kieran

______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: kamccaul@meddent.uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
The fact that no one understands you doesn't make you an artist.


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Friday, 6 March 2009 6:42 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: AW: RE: AW: RE: AW: irecode problem


<> 


No prob, that`s what the list is good for. I would be more interested in a
progress report on your issue :-)



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kieran McCaul
Gesendet: Donnerstag, 5. März 2009 22:35
An: statalist@hsphsun2.harvard.edu
Betreff: st: RE: AW: RE: AW: irecode problem

Thanks Eva and Martin.

I will say in my defence, that I read Nick's article late last night, but
when I woke up this morning, almost the first thing I thought was "Of
course, drop the = and it will build the -irecode- function with the macros,
not the evaluated macros".


______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: kamccaul@meddent.uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
The fact that no one understands you doesn't make you an artist.

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Thursday, 5 March 2009 8:09 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: AW: RE: AW: irecode problem


<> 

Give it a try w/o the equal sign!



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kieran McCaul
Gesendet: Donnerstag, 5. März 2009 11:22
An: statalist@hsphsun2.harvard.edu
Betreff: st: RE: AW: irecode problem

Thanks Martin, but that doesn't help.  Nick is merely pointing out that the
244 character limit can bite. 

______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: kamccaul@meddent.uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
The fact that no one understands you doesn't make you an artist.


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Martin Weiss
Sent: Thursday, 5 March 2009 5:45 PM
To: statalist@hsphsun2.harvard.edu
Subject: st: AW: irecode problem


<> 

With regard to the length issue, have you had a look at
http://www.stata-journal.com/article.html?article=pr0045 yet?




HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kieran McCaul
Gesendet: Donnerstag, 5. März 2009 00:31
An: statalist@hsphsun2.harvard.edu
Betreff: st: irecode problem

My problem is concerned with using the -irecode- function in a program
when the number of cutpoints (the xi used in the function) varies.

I'm accumulating probabilities across a number of groups and then
picking someone from these groups at random based on these
probabilities.  So I've approached this using the -irecode- function.  I
sum the probabilities in each group and then create a running cumulative
probability which I then append to the -irecode- function that I've
store in a local as a string.  When someone is picked, I recalculate the
cumulative probabilities excluding those who have already been picked.
I need to generate the -irecode- function this way because, while I know
how many groups there are to begin with (38), as I progressively pick
individuals, the number of groups will diminish.

The code is below.  There is nothing wrong with it as far as I know and
it will work with a small number of groups, but with a large number of
groups, the string length exceeds the 244 character limit.  So the comm
macro ends up with only the first 244 characters of the command.



* maxg is the total number of groups   
* prob is each person's probability

local p = uniform()   /* generate a probability from U(0,1)  */

local p0 = 0

local comm = "irecode(`p', 0"

/* The total number of groups is maxg
   This loop calculates the total probability in each group,
   adds it to the cumulative probability, 
   and appends it to the string stored in the comm local */

forvalues i = 1/`maxg'  {
	qui summ prob if picked==0 & group==`i'      /* sum of
probabilities in a group  */
	local pg`i' = r(sum)                         /* sum(prob) in
group i  */
	local k = `i'-1                              /* number of
previous group */
	local p`i' = `p`k'' + `pg`i''                /* add this sum to
previous sum  */
	local comm = "`comm'" + ", `p`i''"
}

local comm = "`comm'" + ")"


Now I can get around this, I suppose, by getting rid of the comm macro
altogether and instead using a series of -if- statements.

if `maxg' == 38  {
local group = irecode(`p',0,`p1',`p2',`p3', ...,`p38')
}
else if `maxg' == 37 {
local group = irecode(`p',0,`p1',`p2',`p3', ...,`p37')
}
else if `maxg' == 36 {
local group = irecode(`p',0,`p1',`p2',`p3', ...,`p36')
}
else if `maxg' == 35 {
local group = irecode(`p',0,`p1',`p2',`p3', ...,`p35')
}
etc, etc

But this is a tad inelegant.  Can anyone think of anything more
efficient?


Kieran

______________________________________________
Kieran McCaul MPH PhD
WA Centre for Health & Ageing (M573)
University of Western Australia
Level 6, Ainslie House
48 Murray St
Perth 6000
Phone: (08) 9224-2140
Fax: (08) 9224 8009
email: kamccaul@meddent.uwa.edu.au
http://myprofile.cos.com/mccaul 
http://www.researcherid.com/rid/B-8751-2008
______________________________________________
The fact that no one understands you doesn't make you an artist.



*
*   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/


*
*   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/



*
*   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/


*
*   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/



*
*   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/


*
*   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/



*
*   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/



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