I was trying to determine how to compute confidence intervals after the ttest command, as it doesn't leave behind any scalar or macro for CI. The Stata ttest command uses the invt() function to return the inverse cumulative Student's t-distribution. The help file for the function displays:
However, I discovered that the function returns two different values for the same input: one when used inside the _ttest.ado file and another when used externally. Observe the following trace log:
and now from the Stata command window
I don't understand what's happening. Does it utilize some hidden macros or globals? Such details should have been mentioned in the help file.
Code:
[FN] Statistical functions
(View complete PDF manual entry)
Function
invt(df,p)
Description: the inverse cumulative Student's t distribution: if t(df,t) = p, then invt(df,p) = t
Domain df: 2e-10 to 2e+17 (may be nonintegral)
Domain p: 0 to 1
Range: -8e+307 to 8e+307
However, I discovered that the function returns two different values for the same input: one when used inside the _ttest.ado file and another when used externally. Observe the following trace log:
Code:
. ttest price == 0
One-sample t test
------------------------------------------------------------------------------
Variable | Obs Mean Std. err. Std. dev. [95% conf. interval]
---------+--------------------------------------------------------------------
- _ttest table `level' `"`xname'"' `n' `m' `s'
= _ttest table 95 `"price"' 74 6165.256756756757 2949.495884768919
-------------------------------------------------------------------------- begin _ttest ---
- version 6.0
- gettoken cmd 0 : 0
- if "`cmd'"=="center" {
= if "table"=="center" {
tokenize `"`0'"'
_center `"`1'"' `"`2'"' `"`3'"'
}
- else if "`cmd'"=="center2" {
= else if "table"=="center2" {
tokenize `"`0'"'
_center2 `"`1'"' `"`2'"' `"`3'"'
}
- else if "`cmd'"=="center3" {
= else if "table"=="center3" {
tokenize `"`0'"'
_center3 `"`1'"' `"`2'"' `"`3'"'
}
- else {
- gettoken t1 0 : 0
- gettoken t2 0 : 0
- _`cmd' `"`t1'"' `"`t2'"' `0'
= _table `"95"' `"price"' 74 6165.256756756757 2949.495884768919
----------------------------------------------------------------- begin _ttest._table ---
- args level name n mean sd ztest se
- if "`ztest'" == "" {
= if "" == "" {
- if (`n') == 1 | (`n') == . {
= if (74) == 1 | (74) == . {
local sd = .
}
- local q = invt((`n') - 1,`level'/100)
= local q = invt((74) - 1,95/100)
- dis `q'
= dis 1.992997125889856
1.9929971
- }
- else local q = invnormal((100+`level')/200)
= else local q = invnormal((100+95)/200)
- if ("`ztest'"=="2") {
= if (""=="2") {
local se = `se'
}
- else {
- local se = (`sd')/sqrt(`n')
= local se = (2949.495884768919)/sqrt(74)
- }
- di in smcl in gr %8s abbrev(`"`name'"',8) " {c |}" in ye _col(12) %7.0fc `n' _col(22) %
> 9.0g `mean' _col(34) %9.0g `se' _col(46) %9.0g `sd' _col(58) %9.0g (`mean')-`q'*(`se') _col(70) %9.
> 0g (`mean')+`q'*(`se')
= di in smcl in gr %8s abbrev(`"price"',8) " {c |}" in ye _col(12) %7.0fc 74 _col(22) %9.
> 0g 6165.256756756757 _col(34) %9.0g 342.8719320889989 _col(46) %9.0g 2949.495884768919 _col(58) %9.
> 0g (6165.256756756757)-1.992997125889856*(342.8719320889989) _col(70) %9.0g (6165.256756756757)+1.9
> 92997125889856*(342.8719320889989)
price | 74 6165.257 342.8719 2949.496 5481.914 6848.6
and now from the Stata command window
Code:
. di invt((74) - 1,95/100)
1.6659962
I don't understand what's happening. Does it utilize some hidden macros or globals? Such details should have been mentioned in the help file.
Comment