Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down at the end of May, and its replacement, **statalist.org** is already up and running.

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

From |
Matthew Krauchunas <krauchunasms@mymail.vcu.edu> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Same N when using matrix for ttests |

Date |
Mon, 13 Sep 2010 09:01:20 -0400 |

Hello, I am running a series of ttests to compare my sample to excluded observations. I have adapted Ben Jann's code that I found on Statalist, but I am having a problem in that the same N is being produced for each variable even though I know the Ns are different. Here is the code I am using and the result: * perform t-tests on dependent variables and acuindex. * next set of code from Ben Jann off of Statalist.org http://www.stata.com/statalist/archive/2008-09/msg00385.html capt prog drop myttests program myttests, eclass version 8 syntax varlist [if] [in], by(varname) [ * ] marksample touse markout `touse' `by' tempname Sample_Mean Excluded_Mean Sample_N Excluded_N Sample_StDev Excluded_StDev t_statistic P_Values foreach var of local varlist { qui ttest `var' if `touse', by(`by') `options' mat `Sample_Mean' = nullmat(`Sample_Mean'), r(mu_1) mat `Excluded_Mean' = nullmat(`Excluded_Mean'), r(mu_2) mat `Sample_N' = nullmat(`Sample_N'), r(N_1) mat `Excluded_N' = nullmat(`Excluded_N' ), r(N_2) mat `Sample_StDev' = nullmat(`Sample_StDev' ), r(sd_1) mat `Excluded_StDev' = nullmat(`Excluded_StDev' ), r(sd_2) mat `t_statistic' = nullmat(`t_statistic'), r(t) mat `P_Values' = nullmat(`P_Values' ), r(p) } foreach mat in Sample_Mean Excluded_Mean Sample_N Excluded_N Sample_StDev Excluded_StDev t_statistic P_Values { mat coln ``mat'' = `varlist' } tempname b V mat `b' = `Sample_Mean'*0 mat `V' = `b''*`b' eret post `b' `V' eret local cmd "myttests" foreach mat in Sample_Mean Excluded_Mean Sample_N Excluded_N Sample_StDev Excluded_StDev t_statistic P_Values { eret mat `mat' = ``mat'' } end * dependent variables and variables used in their calculations. * independent variables: organizational characteristics * myttests beds, by(dropped_observations) ereturn list esttab, nomtitle nonumbers noobs cells("Sample_N Sample_Mean Sample_StDev Excluded_N Excluded_Mean Excluded_StDev t_statistic P_Values") Here is the result and the N for all variables is 8,162: -------------------------------------------------------------------------------------------------------------------- Sample_N Sample_Mean Sample_StDev Excluded_N Excluded_M~n Excluded_S~v t_statistic P_Values -------------------------------------------------------------------------------------------------------------------- beds 3282 98.72121 44.74487 4880 94.95512 52.69485 3.359993 .000783 slack 3282 .0975765 .4532256 4880 .0087492 1.090031 4.418613 .0000101 mcal_revenue 3282 .6074439 .1988794 4880 .4182913 .2839123 33.0953 1.7e-225 dependenc~15 3282 .4146383 .1492982 4880 .2812511 .1981935 32.80157 8.8e-222 dependenc~25 3282 .411041 .1445903 4880 .2812352 .1952051 32.55888 9.9e-219 -------------------------------------------------------------------------------------------------------------------- However, the N is 9,476 when I run beds alone: Sample_N Sample_Mean Sample_StDev Excluded_N Excluded_M~n Excluded_S~v t_statistic P_Values -------------------------------------------------------------------------------------------------------------------- beds 3282 98.72121 44.74487 6194 88.95802 70.55003 7.197858 6.58e-13 -------------------------------------------------------------------------------------------------------------------- Does anyone have any suggestions on how to run the ttests and account for the different Ns? Thank you, Matt * * 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/

**Follow-Ups**:**Re: st: Same N when using matrix for ttests***From:*Scott Merryman <scott.merryman@gmail.com>

- Prev by Date:
**RE: st: RE: RE: RE: problem with commands** - Next by Date:
**st: Brant test after oprobit: Help with syntax?** - Previous by thread:
**st: marginal effect after cmp - combining results from two equations** - Next by thread:
**Re: st: Same N when using matrix for ttests** - Index(es):