[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Patrick McElduff" <[email protected]> |

To |
<[email protected]> |

Subject |
st: returning value from a program |

Date |
Wed, 21 Dec 2005 12:25:01 +1100 |

Dear Nick Unless I am mistaken 'predict' doesn't give the information I need and therefore your reply isn't particulary helpful. The code by Joe Hibe takes 3 arguements and does work. His code can easily be modified to take two arguements as one of the first lines of his code combines two of the arguements into one variable, but as you say it isn't suitable for conversion into a function because it drops all the variables and then creates a different structure for the dataset. My code does the calculation correctly and will provide the answer if the dataset is structured properly. But I know that it is simple and incorrect. My question is, can the program be modified into a function that takes two arguements from each observation and returns a value to a new variable? If so then I can spend time working on correcting the program. Thanks Patrick >>> [email protected] 21/12/2005 10:23:11 am >>> Joe Hilbe has used the name -cpoisson- for two quite different programs, for cumulative and for censored Poisson. The first, published in STB-1, sounds closer to what you want, but it long predates the -poisson- command, and it is not compatible with that. Also, it -drop-s all data in memory without warning!!! My guess is that your own program needs a lot of changes before it will work. You are putting constants in variables (not illegal, but inefficient) and variables in constants (usually fatal). The line local cum = `cum' = ((exp(-poi_pred)*(poi_pred^`i'))/`fact') even after correcting the second = to + is not going to work the way you want it to. I recommend keeping much closer to what -predict- can supply for you. Nick [email protected] Patrick McElduff > Hi Nick > > What I am attempting to do (and there may be a much more > simple solution) is to calculate the exact probability of > observing a value of x or greater given that I expect to > observe mu. The value of mu comes from a poisson regression > and is potentially different for each observed value. > > The code that I believe works is: > > generate temp = 0 > > local i = 0 > local cum = 0 > generate prob = 0 > > while `i' <= cases { > local j = 1 > local fact = 1 > > while `j' <= `i' { > local fact = `fact' * `j' > local j = `j' + 1 > } > > local cum = `cum' = ((exp(-poi_pred)*(poi_pred^`i'))/`fact') > local i = `i' + 1 > replace prob = 1 - `cum' if `i' == cases & cases ~= 0 > replace prob = 1 if cases == 0 > } > > There is also a program called cpoisson by Joseph Hilbe that > can by easily modified to work for my scenario but it doesn't > seem to return the answer the way I need it to. > >>> [email protected] 21/12/2005 8:46:33 am >>> > You can't write a program with exactly > this syntax. You could write an -egen- > function. > > If you want a new variable as output, > why this question? > > I could start speculating on what you might mean, > but better that you should tell us much more. > > Indeed, please show us your program. > > Nick > [email protected] > > Patrick McElduff > > > I want to write a program that has two arguements and > > returns a value so that I can use it in the form: > > > > generate temp = program(var1 var2) > > > > I have written the guts of the program to do the work but I > > don't know how to get the input and output in the form I want. > > > > Could you please tell me where I should start looking. > * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/ * * For searches and help try: * http://www.stata.com/support/faqs/res/findit.html * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

- Prev by Date:
**st: RE: RE: returning value from a program** - Next by Date:
**st: RE: returning value from a program** - Previous by thread:
**st: returning value from a program** - Next by thread:
**st: RE: returning value from a program** - Index(es):

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