I would agree that you should start by reshaping the data to long.
However, the next step might be to use -parmby- (part of the -parmest-
package) together with -somersd- (part of the -somersd- package) to
create an output dataset (or resultsset) with 1 observation per
individual ID and data on estimates, confidence intervals and P-values
for that individual's tau-a parameter. That way, you have a confidence
interval and a P-value for each estimated individual tau-a, not just an
estimate.
The -somersd- and -parmest- packeges can be downloaded from SSC using
the -ssc- command. More documents about -somersd- and -parmest- can be
downloaded from my website (see my signature below).
I hope this helps.
Roger
Roger Newson
Lecturer in Medical Statistics
Respiratory Epidemiology and Public Health Group
National Heart and Lung Institute
Imperial College London
Royal Brompton campus
Room 33, Emmanuel Kaye Building
1B Manresa Road
London SW3 6LR
UNITED KINGDOM
Tel: +44 (0)20 7352 8121 ext 3381
Fax: +44 (0)20 7351 8322
Email: r.newson@imperial.ac.uk
www.imperial.ac.uk/nhli/r.newson/
Opinions expressed are those of the author, not of the institution.
-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Nick Cox
Sent: 17 November 2006 11:43
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: running -ktau- and storing its results for each
observation
I agree that you would be better off with the data
-reshape-d to long.
After that one standard protocol is of this form
levelsof id, local(ids)
gen corr = .
qui foreach i of local ids {
ktau rank90 rank05 if id == `i'
replace corr = r(tau_a) if id == `i'
}
After that, each correlation for each individual is necessarily
repeated for each observation for that individual.
You can tag just one observation from each group
using -egen, tag()-.
For more on -foreach- see for example
[P] foreach . . . . . . . . . . . . . . . . . . . . . . . Loop over
items
(help foreach)
FAQ . . . . . . . . . . Making foreach go through all values of a
variable
8/05 Is there a way to tell Stata to try all values of a
particular variable in a foreach statement without
specifying them?
http://www.stata.com/support/faqs/data/foreach.html
FAQ . . . . . . . . . Counting distinct strings across a set of
variables
7/04 How do I count the number of distinct strings
across a set of variables?
http://www.stata.com/support/faqs/data/distinctstrings.html
FAQ . . . . . . . . . . . . . . Getting nice time of day labels on a
graph
9/03 How can I get "nice" time of day labels on a graph?
http://www.stata.com/support/faqs/graphics/nicetime.html
Example . . . . Stata learning module: Working across variables using
foreach
. . . . . . . . . . . . . . . . . . UCLA Academic Technology
Services
8/03
http://www.ats.ucla.edu/stat/stata/modules/acrossvars.htm
SJ-3-2 pr0009 . . . . . . . . . . . . . Speaking Stata: Problems with
lists
Q2/03 SJ 3(2):185--202 (no
commands)
discusses ways of working through lists held in macros
SJ-2-2 pr0005 . . . . . . Speaking Stata: How to face lists with
fortitude
Q2/02 SJ 2(2):202--222 (no
commands)
demonstrates the usefulness of for, foreach, forvalues, and
local macros for interactive (non programming) tasks
There are also other versions of the last on the internet, as a Google
will show.
Nick
n.j.cox@durham.ac.uk
Kelvin Foo
> I have a dataset where individuals rank items from 1 to 10 in the
> years 1990 and 2005. I would like to find the Kendall's tau statistic
> for each individual's rankings of items between these two years, and
> store the results in a new variable. In my dataset, the individuals
> are the observations and the rankings are stored in 20 variables,
> named A_90, B_90... J_90, A_05, B_05,.. J_05. A to J are the 10 items
> and '90', '05' are the years.
>
> How can I carry out this task?
>
> My guess is to first use -reshape- to have 1990's rankings stored in
> one variable (rank90), and 2005's rankings in another variable
> (rank05). Each individual would have an identifier number associated
> with him, and this will appear 10 times in the reshaped long format.
>
> Next, I was thinking of running
>
> generate correl=. // variable for storing Kendall tau results
> by identifier: ktau rank90 rank05
>
> But how do I get Stata to store the r(tau_a) result in correl for each
> individual before moving on to the next one?
>
> Or is there an alternative way in which I can find the Kendall tau for
> each observation, given that my rankings are stored across different
> variables?
*
* 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/