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

st: R: Mata question

From   "Carlo Lazzaro" <>
To   <>
Subject   st: R: Mata question
Date   Sat, 4 Jul 2009 10:45:45 +0200

Dear Christian,
the following is a temptative answer to your query, not in Mata language.
Let's assume we have 20 + 20 sample means and sds (sample size: 10
observations each) drawn from 2 different populations (I mean, 20 from
population1 and 20 from population 2). Sample means and sds drawn from
population 1 are labelled a and c. Sample means and sds drawn from
population 2 are labelled b and d. Ttests are performed under the equal
variance assumption. Example stops at Student t retrieving and storing for
each ttest performed (two-sided p-value was not included in the Stata .do

set obs 20
g a==2*uniform()
g b=1*uniform()
g  c=.03*uniform()
g d =.03*uniform()
g double student_t=.
qui forval i = 1/20 {
g t`i' = (a[`i']-b[`i'])/(c[`i']^2/10+d[`i']^2/10)^.5
sum t`i', meanonly
replace  student_t=r(mean) in `i'
drop t`i'

Not that elegant, but I do hope this help.

Kind Regards,
-----Messaggio originale-----
[] Per conto di Christian
Inviato: sabato 4 luglio 2009 9.15
A: Statalist
Oggetto: st: Mata question

Hi all

I'm trying to do a loot with a nested -ttesti- but I couldn't do it. I
have two vector with different means (m1 and m2) and another two with
each mean's standard deviation (s1 and s2). This vectors are quite
large, so do -ttesti- element for element could be very costly. Also,
I have each sample's size on two variables: n1 and n2. All this values
are obtained from a logistic regresion. After run -ttesti- I want to
save the t-statistic -r(t)- and the probability for two-sided p-value
-r(p)-. I'm doing something like this:

forvalues i=1/size(m1) {    /* how can i get vector's size? */
		ttesti n1 m1[1,`i'] s1[1,`i'] n1 m1[1,`i'] s1[1,`i']
		mat tvalues[1,`i']=r(t)
		mat pvalues[1,`i']=r(p)

But appears a lot of errors: 1) n1 should be integer. 2) 'm1' found
where number expected. 3) varlist not allowed.
How can I solve this?


*   For searches and help try:

*   For searches and help try:

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