Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: returning a value from a program


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: returning a value from a program
Date   Tue, 3 Jan 2006 00:21:18 -0000

We, meaning the Editors of the Stata Journal, 
will negotiate with Joe about reissue of the 
original -cpoisson- and -epoisson- commands from 
STB-1 under different names. They are, in current terms, 
immediate commands and would be better labelled
as such. 

Regardless of when temporary variables were introduced 
into Stata, using any kind of variables for the calculations 
tackled by Joe is not essential, and indeed never was.  

Nick 
[email protected] 

[email protected]
21 December 2005 17:38
 
> I noticed the the discussion regarding exact  poisson 
> probabilities on the 
> list. I get the digest only, so have had to respond  later. 
> 
> I did indeed make a mistake with naming two programs by the 
> same  name. The 
> current -cpoisson is a censored poisson written using version 
> 9.1  code. It is 
> found on the SSC site. I had forgotten that I wrote another 
> back in  1991. The 
> -cpoisson- I wrote for STB-1 in May 1991 calculated 
> cumulative poisson  
> probabilities. However, there is another program that was 
> published together  with 
> it that calculates exact poisson probabilities, called 
> -epoisson.ado-. Is  
> this more of what you want? One simply provides the 
> population ratio (mu), the  
> number of observations, and the number of cases. The exact 
> poisson probability  
> is thereupon displayed. An example is provided in the help 
> file, which can be 
>  downloaded from the web. 
> 
> I have pasted the file code into this email  below. Note that 
> it uses version 
> 2.1 code and creates new variables, and at the  end erases 
> all variables in 
> memory. Like the old -cpoisson- program, it was  meant to be 
> used without 
> anything else in memory. As I recall, Stata had not yet  
> developed the temp 
> variable class. It didn't come out until version 3. And there 
>  may have been problems 
> using the program if data was already in memory. Instead  of 
> the -drop _all - 
> code, you can replace it with dropping just those variables  
> that were 
> created by the program. Of course, it is preferable to just 
> rewrite it  with 
> tempvars and in current code. This would eliminate any such 
> problems.  
> 
> Isn't there another function in Stata that calculates exact 
> and  cumulative 
> poisson probabilities? These were the first two programs 
> written for  the STB 
> some 16 years ago. I haven't checked, but it seems that Stata 
> should  have a 
> function for it that can be used in your program. 
> 
> Joe  Hilbe
> 
> 
> /* DATE 4\24\91  */
> /*     EXACT  POISSON PROBABILITY
> Joseph Hilbe -  STB       */
> 
> program define  epoisson
> version 2.1
> if "%_3"=="" {
> di in re "Type 3  arguments:"
> di in re "     pop ratio   observations   cases"
> exit 198
> }
> drop _all
> quietly  {
> set obs %_3
> if (%_3<1) {
> set obs 1
> gen double  expect=%_1*%_2
> di in gr "Exact poisson probability  => " in ye exp(-expect)
> }
> if (%_3>0)  {
> gen double expect=%_1*%_2
> gen double prob=exp(-expect)
> gen  double cum=1
> gen num=[_n-1]+1
> 
> while  num-1<_N {
> replace cum=cum*num
> replace num=num+1 
> }
> replace  prob=(expect^%_3)*(exp(-expect))/cum
> di in gr "Exact poisson  probability => " in ye prob
> }
> }
> drop _all
> end  

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



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