⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sampsi.ado

📁 是一个经济学管理应用软件 很难找的 但是经济学学生又必须用到
💻 ADO
📖 第 1 页 / 共 2 页
字号:
				*/ "Estimated required sample size:" /*
				*/ _n(2) _col(14) "n = " in ye %8.0f `n1' 

			}
			else {  /* two sample */
				if `sd2' == 0 { local sd2 = `sd1' }
				local n1 = `w'*((`sd1')^2+(`sd2')^2/`ratio')
				if `n1' ~= int(`n1') { 
					local n1 = int(`n1' + 1) 
				}
				local n2 = `ratio'*`n1'
				if `n2' ~= int(`n2') { 
					local n2 = int(`n2' + 1) 
				}
				di _n in gr "Estimated sample size for"  /*
				*/ " two-sample comparison of means" _n(2) /*
				*/ "Test Ho: m1 = m2, where m1 is the mean" /*
				*/ " in population 1" _n _col(21) /*
				*/ "and m2 is the mean in population 2" /*
				*/  _n "Assumptions:" _n(2) _col(10) /*
				*/  "alpha = " in ye %8.4f `alpha' _c 
				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
				} 
				di _col(10) in gr "power = " in ye %8.4f /*
				*/  `power' _n in gr _col(13) "m1 = " /*
				*/ in ye %8.0g `m1' _n in gr _col(13) "m2 = " /*				*/  in ye %8.0g `m2' _n in gr _col(12) /*
				*/ "sd1 = " in ye %8.0g `sd1' _n in gr /*
				*/ _col(12) "sd2 = " in ye %8.0g `sd2' _n /*
				*/ in gr _col(10) "n2/n1 = " in ye %8.2f /*
				*/ `ratio' _n(2) in gr /*
				*/ "Estimated required sample sizes:" /*
				*/ _n(2) _col(13) "n1 = " in ye %8.0f `n1' _n /*
				*/ in gr _col(13) "n2 = " in ye %8.0f `n2'  

			}

		}
		else { /* proportions */
			if "`onesamp'"~="" {  /* one sample */
				local n1 = /*
				*/ ((`za'*sqrt(`w1')+`zb'*sqrt(`w2'))/`diff')^2
				if `n1' ~= int(`n1') { 
					local n1 = int(`n1' + 1) 
				}
				di _n in gr "Estimated sample size for " /*
				*/ "one-sample comparison of proportion" _n /*
				*/ "  to hypothesized value" _n(2) /* 
				*/ "Test Ho: p = " in ye %6.4f `m1' in gr /*
				*/ ", where p is the proportion in the" /*
				*/ " population" _n(2) "Assumptions:" /*
				*/  _n(2) _col(10) "alpha = " in ye %8.4f /*
				*/  `alpha' _c 
				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
				}
				di _col(10) in gr "power = " in ye %8.4f /*
				*/ `power' _n in gr " alternative p = " /*
				*/  in ye %8.4f `m2' _n(2) in gr /*
				*/  "Estimated required sample size:" /*
				*/  _n(2) _col(14) "n = " in ye %8.0f `n1'
			}
			else {  /* two sample */
				scalar `r1' = `ratio' + 1
				scalar `pbar' = (`m1'+`ratio'*`m2')/`r1'
				scalar `n0' = /*
				*/ (`za'*sqrt(`r1'*`pbar'*(1-`pbar')) /*
			 	*/ +`zb'*sqrt(`ratio'*`w1'+`w2'))^2 /*
				*/ /(`ratio'*(`diff')^2) 
				
	
				/***without continuity correction***/
								
				if "`continuity'"==""{
					local n1 = (`n0'/4)*(1+ /*
					*/ sqrt(1+2*`r1'/(`n0'*`ratio'*`diff')))^2
				}
				else{
					local n1=`n0'
				}									

				if `n1' ~= int(`n1') { 
					local n1 = int(`n1' + 1) 
				}
				local n2 = `ratio'*`n1'
				if `n2' ~= int(`n2') { 
					local n2 = int(`n2' + 1) 
				}
				di _n in gr "Estimated sample size for " /*
				*/ "two-sample comparison of proportions" /*
				*/  _n(2) "Test Ho: p1 = p2, where p1 is " /*
				*/ "the proportion in population 1" _n  /*
				*/ _col(21) "and p2 is the proportion in " /*
				*/ "population 2" _n "Assumptions:" _n(2) /*
				*/  _col(10) "alpha = " in ye %8.4f `alpha' _c 

				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)"
				} 
				di _col(10) in gr "power = " in ye %8.4f /*
				*/  `power' _n in gr _col(13) "p1 = " /*
				*/ in ye %8.4f `m1' _n in gr _col(13) /*
				*/  "p2 = " in ye %8.4f `m2' _n in gr /*
				*/ _col(10) "n2/n1 = " in ye %6.2f `ratio' /*
				*/ _n(2) in gr/*
				*/  "Estimated required sample sizes:"/*
				*/  _n(2) _col(13) "n1 = " in ye %8.0f `n1'/*
				*/  _n in gr _col(13) "n2 = " in ye %8.0f `n2' 		
			}
		}
	}
	/* Compute power. */
	else {
		if `n2' == 0 {  /* determine n2 from n1 and ratio */
			local n2 = `ratio'*`n1'
			if `n2' ~= int(`n2') { local n2 = int(`n2' + 1) }
		}
		else if `n1' == 0 {  /* determine n1 from n2 and ratio */
			local n1 = `n2'/`ratio'
			if `n1' ~= int(`n1') { local n1 = int(`n1' + 1) }
		}
		if `sd1' ~= 0 | `sd2' ~= 0 { /* means */
			if `sd1' == 0 { local sd1 = `sd2' }
			if "`onesamp'"~="" {  /* one sample */
				local power = /*
				*/ normprob(`diff'*sqrt(`n1')/`sd1' - `za')
				di _n in gr /*
		       		*/ "Estimated power for one-sample " /*
				*/ "comparison of mean" /*
				*/ _n "  to hypothesized value" _n(2) /*
				*/ "Test Ho: m = " in ye %6.0g `m1' in gr /*
				*/ ", where m is the mean in the population" /*
				*/ _n(2) "Assumptions:" _n(2) _col(10) /*
				*/ "alpha = " in ye %8.4f `alpha' _c 
				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
					local power = `power' + /*
				*/ normprob(-`diff'*sqrt(`n1')/`sd1' - `za')
				}
				di in gr " alternative m = " in ye %8.0g /*
				*/ `m2' _n in gr _col(13) "sd = " in ye /*
				*/ %8.0g `sd1' _n in gr " sample size n = " /*
				*/ in ye %8.0f `n1' _n(2) in gr /*
				*/ "Estimated power:" _n(2) _col(10) /*
				*/ "power = " in ye %8.4f `power' 

			}
			else {  /* two sample */
				if `sd2' == 0 { local sd2 = `sd1' }
				scalar `w' = sqrt((`sd1')^2/`n1' + (`sd2')^2/`n2')
				local power = normprob(`diff'/`w' - `za')
				di _n in gr /*
				*/ "Estimated power for two-sample " /*
				*/ "comparison of means" _n(2) /*
				*/ "Test Ho: m1 = m2, where m1 is the mean "/*
				*/ "in population 1" _n _col(21) /*
				*/ "and m2 is the mean in population 2" /*
				*/ _n "Assumptions:" _n(2) _col(10) /*
				*/ "alpha = " in ye %8.4f `alpha' _c 

				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
					local power = `power' + /*
					*/ normprob(-`diff'/`w' - `za')
				} 

				di in gr _col(13) "m1 = " in ye %8.0g `m1' /*
				*/ _n in gr _col(13) "m2 = " in ye %8.0g /*
				*/ `m2' _n in gr _col(12) "sd1 = " /*
				*/ in ye %8.0g `sd1' _n in gr _col(12) /*
				*/ "sd2 = " in ye %8.0g `sd2' _n in gr /*
				*/ "sample size n1 = " in ye %8.0f `n1' _n /*
				*/ in gr _col(13) "n2 = " in ye %8.0f `n2' /*
				*/ _n in gr _col(10) "n2/n1 = " in ye %8.2f /*
				*/ `n2'/`n1' _n(2) in gr "Estimated power:" /*
				*/ _n(2) _col(10) "power = " in ye %8.4f /*
				*/ `power'

			}
		}
		else { /* proportions */

			local assump1=((`m1'*`n1')>=10)*(((1-`m1')*`n1')>=10)
			local warning = 0

			if "`onesamp'"~="" {  /* one sample */
				local power = normprob((`diff'*sqrt(`n1')/*
				*/ - `za'*sqrt(`w1'))/sqrt(`w2'))

				di _n in gr "Estimated power for one-sample " /*
				*/ "comparison of proportion" _n /*
				*/ "  to hypothesized value" _n(2) /*
				*/ "Test Ho: p = " in ye %6.4f `m1' in gr /*
				*/ ", where p is the proportion in the " /*
				*/ "population" _n(2) "Assumptions:" _n(2) /*
				*/ _col(10) "alpha = " in ye %8.4f `alpha' _c 
				 if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else{ 
					di in gr "  (two-sided)" 
					local power = `power' /*
					*/ + normprob((-`diff'*sqrt(`n1') /*
					*/ - `za'*sqrt(`w1'))/sqrt(`w2'))
				} 
			 	di in gr " alternative p = " in ye %8.4f /*
				*/ `m2' _n in gr " sample size n = " in ye /*
				*/ %8.0f `n1' _n(2) in gr "Estimated power:" /*
				*/ _n(2) _col(10) "power = " in ye %8.4f /*
				*/ `power' 
				if (~`assump1'){
					local warning = 1
					di ""
					di in smcl as txt "{p 0 6 4}Note: For the above sample "/*
						*/"size(s) and proportion(s), the normal "/*
						*/"approximation to the binomial may not be very "/*
 						*/"accurate.  Thus, power calculations are " /*
				                */"questionable.{p_end}"
				}
 
			}
			else {  /* two sample */
				
				local assump2=((`m2'*`n2')>=10)*(((1-`m2')*`n2')>=10)
									
				local ratio = `n2'/`n1'
				scalar `r1' = `ratio' + 1
				scalar `pbar' = (`m1'+`ratio'*`m2')/`r1'

				/***without continuity correction***/
								
				if "`continuity'"==""{
					scalar `n0' = /*
					*/ (`n1'- `r1'/(2*`ratio'*`diff'))^2/`n1'
				}
				else{
					scalar `n0'=`n1'
				}
				


				scalar `zb' = (`diff'*sqrt(`ratio'*`n0') - /*
				*/ `za'*sqrt(`r1'*`pbar'*(1-`pbar'))) /*
				*/ /sqrt(`ratio'*`w1'+`w2') 
				local power = normprob(`zb') 
				di _n in gr "Estimated power for two-sample " /*
				*/ "comparison of proportions" _n(2) /*
				*/ "Test Ho: p1 = p2, where p1 is the " /*
				*/ "proportion in population 1" _n _col(21) /*
				*/ "and p2 is the proportion in population 2" /*
				*/ _n "Assumptions:" _n(2) _col(10) /*
				*/ "alpha = " in ye %8.4f `alpha' _c
				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else{ 
					di in gr "  (two-sided)"
				} 
				di in gr _col(13) "p1 = " in ye %8.4f `m1' /*
				*/ _n in gr _col(13) "p2 = " in ye %8.4f /*
				*/ `m2' _n in gr "sample size n1 = " in ye /*
				*/ %8.0f `n1' _n in gr _col(13) "n2 = " /*
				*/ in ye %8.0f `n2' _n in gr _col(10) /*
				*/ "n2/n1 = " in ye %8.2f `n2'/`n1' _n(2) /*
				*/ in gr "Estimated power:" _n(2) _col(10) /*
				*/ "power = " in ye %8.4f `power' 
				if (~(`assump1'*`assump2')){
					local warning = 1
					di ""
					di in smcl as txt "{p 0 6 4}Note: For the above sample "/*
						*/"size(s) and proportion(s), the normal "/*
						*/"approximation to the binomial may not be very "/*
						*/"accurate.  Thus, power calculations are " /*
 				                */"questionable.{p_end}"
				}
			}
			global S_w = `warning'
		}
	}
	global S_1 = `n1'
	global S_2 = `n2'
	global S_3 = `power'
end

program define _MASs, rclass
	gettoken m1 0 : 0, parse(" ,")
	gettoken m2 0 : 0, parse(" ,")

	confirm number `m1'
	confirm number `m2'

	local dalpha = 1 - $S_level/100
	syntax [, Alpha(real `dalpha') Power(real 0.90) N1(int 0) N2(int 0) /*
	*/  SD1(real 0) SD2(real 0) Ratio(real 1) ONESAMple ONESIDed ]
	if `n1' == 0 & `n2' == 0 {  /* compute sample size */
		if "`onesamp'"~="" {  /* one sample */
			di _n in gr /*
			*/ "Estimated sample size for one sample " /*
			*/ "with repeated measures" /*
			*/ _n(1) "Assumptions:" _n(1) _col(39) /*
			*/  "alpha = " in ye %8.4f `alpha' _c 
			if "`oneside'"~="" { 
				di in gr "  (one-sided)" 
			} 
			else { 
				di in gr "  (two-sided)" 
			} 
			di _col(39) in gr "power = " in ye %8.4f /*
			*/  `power' _n in gr _col(30) " alternative m = " /*
			*/ in ye %8.0g `m2' _n in gr _col(42) "sd = " /*
			*/ in ye %8.0g `sd1' 
			global S_5 = "sample" 
			exit

		}
		else {  /* two sample */
			di _n in gr "Estimated sample size for"  /*
			*/ " two samples with repeated measures" /*
			*/  _n "Assumptions:" _n(1) _col(10) /*
			*/  "alpha = " in ye %8.4f `alpha' _c 
			if "`oneside'"~="" { 
				di in gr "  (one-sided)" 
			} 
			else { 
				di in gr "  (two-sided)" 
			} 
			di _col(39) in gr "power = " in ye %8.4f /*
			*/  `power' _n in gr _col(42) "m1 = " /*
			*/ in ye %8.0g `m1' _n in gr _col(42) "m2 = " /*
			*/  in ye %8.0g `m2' _n in gr _col(41) /*
			*/ "sd1 = " in ye %8.0g `sd1' _n in gr /*
			*/ _col(41) "sd2 = " in ye %8.0g `sd2' _n /*
			*/ in gr _col(39) "n2/n1 = " in ye %8.2f /*
			*/ `ratio' 
			global S_5 = "sample" 
			exit
		}
	}
	/* Compute power. */
	else {
		if `n2' == 0 {  /* determine n2 from n1 and ratio */
			local n2 = `ratio'*`n1'
			if `n2' ~= int(`n2') { local n2 = int(`n2' + 1) }
		}
		else if `n1' == 0 {  /* determine n1 from n2 and ratio */
			local n1 = `n2'/`ratio'
			if `n1' ~= int(`n1') { local n1 = int(`n1' + 1) }
		}
		if `sd1' ~= 0 | `sd2' ~= 0 { /* means */
			if "`onesamp'"~="" {  /* one sample */
				di _n in gr /*
		       		*/ "Estimated power for one sample " /*
				*/ "with repeated measures" /*
				*/ _n "Assumptions:" _n(1) _col(39) /*
				*/ "alpha = " in ye %8.4f `alpha' _c 
				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
				}
				di in gr _col(30) " alternative m = " /*
				*/ in ye %8.0g /*
				*/ `m2' _n in gr _col(42) "sd = " in ye /*
				*/ %8.0g `sd1' _n in gr _col(30) /*
				*/ " sample size n = " /*
				*/ in ye %8.0f `n1'  
				global S_5 = "power" 
				exit
			}
			else {  /* two sample */
				di _n in gr /*
				*/ "Estimated power for two samples " /*
				*/ "with repeated measures" /*
				*/ _n "Assumptions:" _n(1) _col(39) /*
				*/ "alpha = " in ye %8.4f `alpha' _c 

				if "`oneside'"~="" { 
					di in gr "  (one-sided)" 
				} 
				else { 
					di in gr "  (two-sided)" 
				} 

				di in gr _col(42) "m1 = " in ye %8.0g `m1' /*
				*/ _n in gr _col(42) "m2 = " in ye %8.0g /*
				*/ `m2' _n in gr _col(41) "sd1 = " /*
				*/ in ye %8.0g `sd1' _n in gr _col(41) /*
				*/ "sd2 = " in ye %8.0g `sd2' /*
				*/ _n in gr _col(30) /*
				*/ "sample size n1 = " in ye %8.0f `n1' _n /*
				*/ in gr _col(42) "n2 = " in ye %8.0f `n2' /*
				*/ _n in gr _col(39) "n2/n1 = " in ye %8.2f /*
				*/ `n2'/`n1' 
				global S_5 = "power" 
				exit
			}
		}
	}
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -