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

st: RE: sample size program


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: sample size program
Date   Tue, 28 Jan 2003 11:21:33 -0000

Sophie Barthel
>
> The following program is one for a sample size calculation. I am not
> using sampsi because I want to extend the program later. However, on
> running it in stata it returns an error which I can't seem
> to spot at
> the moment.
>
> program define sampsi1
>
> version 7.0
>
> syntax [, ZAlpha (real 1.645) ZPower (real 0.8416) HRatio (real 1.5)
> Censor (real 0.8) PControl (real 0.5)]
>
> if "`ZAlpha'"=="{
> ret local errmess "zalpha required"
> exit 198
> }
>
> if `zalpha'<=0 {
> ret local errmess "zalpha() out of range"
> exit 198
> }
>
> if "`ZPower'"=="{
> ret local errmess "zpower required"
> exit 198
> }
>
> if `zpower'<=0 {
> ret local errmess "zpower() out of range"
> exit 198
> }
>
> if "`HRatio'"=="{
> ret local errmess "hratio required"
> exit 198
> }
>
> if `hratio'<=0 {
> ret local errmess "hratio() out of range"
> exit 198
> }
>
> if "`CEnsor'"=="{
> ret local errmess "censor required"
> exit 198
> }
>
> if `censor'<0 | `censor'>1 {
> ret local errmess "censor() out of range"
> exit 198
> }
>
> if "`PControl'"=="{
> ret local errmess "pcontrol required"
> exit 198
> }
>
> if `pcontrol'<0 | `pcontrol'>1 {
> ret local errmess "pcontrol() out of range"
> exit 198
> }
>
> tempname N0 N1 N2 N
>
> scalar `N0' = (`ZAlpha'+`ZPower')^2
>
> scalar `N1'=(log(`HRatio'))^2
>
> scalar `N2'=`Censor'*`PControl'*(1-`PControl')
>
> scalar `N'=`N0'/(`N1'*`N2')
>
> return N=`N'
>
> end
>
> exit
>

I think most of the answers you need
lie in a detailed scrutiny of the help for
-syntax-. As all options are required, and
all have legal ranges, those facts should
be indicated in the -syntax- statement.

Next, capitalisation within -syntax- indicates allowed
abbreviations, not macro names.

The program should also be declared rclass.

Here is a second stab. Untested.

program define sampsi1, rclass
	version 7.0
	syntax , ZAlpha(numlist >0) Zpower(numlist >0) /*
      */ Hratio(numlist >0) /*
	*/ Censor(numlist >=0 <=1) PControl(numlist >=0 <=1)

	tempname N0 N1 N2 N
	scalar `N0' = (`zalpha' + `zpower')^2
	scalar `N1' = (log(`hratio'))^2
	scalar `N2' = `censor' * `pcontrol' * (1 - `pcontrol')
	scalar `N' = `N0' / (`N1' * `N2')

	return scalar N = `N'
end

Nick
[email protected]

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