Dear Nick:
I used your command lines and it works perfectly.
In order to get a tab-delimited file, and following your help on previous postings, I wrote the following command lines:
foreach var of varlist index2 prov_ass {
egen rank_`var' = rank(`var') if sodas3cl < .
bysort sodas3cl : egen ranksum_`var' = sum(rank_`var')
by sodas3cl : egen rankmean_`var' = mean(rank_`var')
tabstat rankmean_`var', by(sodas3cl) save
tabstatmat statdes3
mat2txt, matrix(statdes3) saving(statdes3) append
}
My problem is the following:
At the end of the loop, the first time, I should have -replace- and the subsequent times -append-. I don't know how can I make Stata understand this difference in a loop.
Best regards
Herv�
? Is there a possibility with matrices (-makematrix-, -mat2txt-, or another command)?
Best regards
Herv�
***********************************************************
Professeur/Professor
Coordinateur du D�partement/Head of Department
HEC Paris
D�partement Comptabilit� Contr�le de gestion / Dept of Accounting and Management Control
1, rue de la Liberation
78351 - Jouy-en-Josas
France
Tel: +33 1 39 67 94 42 - Fax: +33 1 39 67 70 86
[email protected]
http://campus.hec.fr/profs/stolowy/perso/home.htm
>>> [email protected] 11/06/05 6:15 PM >>>
In addition to Kit's suggestions, note that
the sum of ranks and the mean rank are nothing
exotic, and so are also obtainable directly:
sysuse auto, clear
egen rank = rank(mpg) if rep78 < .
bysort rep78 : egen ranksum = sum(rank)
by rep78 : egen rankmean = mean(rank)
tabdisp rep78 if rep78 < . , c(ranksum rankmean) format(%5.1f)
----------------------------------
Repair |
Record |
1978 | ranksum rankmean
----------+-----------------------
1 | 72.5 36.3
2 | 220.5 27.6
3 | 905.0 30.2
4 | 688.5 38.3
5 | 528.5 48.0
----------------------------------
. kwallis mpg, by(rep78)
Test: Equality of populations (Kruskal-Wallis test)
+------------------------+
| rep78 | Obs | Rank Sum |
|-------+-----+----------|
| 1 | 2 | 72.50 |
| 2 | 8 | 220.50 |
| 3 | 30 | 905.00 |
| 4 | 18 | 688.50 |
| 5 | 11 | 528.50 |
+------------------------+
Nick
[email protected]
Kit Baum
> Herve S. says
>
> I run the Kruskal - Wallis tests of differences between groups. (In
> reality, I use a variation -kwallis2- [donwloadable from ssc] which
> provides the rank mean as well as the rank sum (-kwallis- only
> provides the ranksum).
>
> kwallis2 index2, by(sodas3cl)
> (snip)
>
> This code was written by another Herve, Herve Caci, back in 1999 for
> Stata 5.0. Back then there was not the simple means of returning
> items in a return list (one could return macros in S_1, S_2,
> etc. and
> it does return a few--presumably not the ones you need).
>
> Make a copy of kwallis2.ado (kwallis3.ado?), change the version
> number to something more recent (e.g. version 8.2), change the
> program define line to read "program define kwallis3, rclass"
> and see
> if the routine still runs and generates the same results. If so, add
> return statements for each item you would like to use after the
> routine runs. E.g. `Mean'`[`i'] (which is the i'th observation of a
> tempvar named `Mean') is the rank mean for the i-th group. Put it in
> a scalar and return it, e.g.
>
> return scalar mean1 = `Mean'[1]
> etc.
>
> These items will then show up in your return list.
*
* 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/
*
* 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/