Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: reshaping a data file: cell frequency = number of rows in the new data set


From   "Scott Merryman" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: reshaping a data file: cell frequency = number of rows in the new data set
Date   Fri, 17 Dec 2004 05:01:43 -0600

> -----Original Message-----
> From: [email protected] [mailto:owner-
> [email protected]] On Behalf Of G. ter Riet
> Sent: Friday, December 17, 2004 2:20 AM
> To: [email protected]
> Subject: st: RE: reshaping a data file: cell frequency = number of rows in
> the new data set
> 
> Hi Scott,
> I apologize. To answer your question,
> now the data are structured as (data editor view)
> a b c d
> 1 2 3 4
> where a thru' d are the variable names denoting the cell frequencies;
> a=true positive test results; b=false positives; c=false negatives;
> d=true negatives.
> 
> Gerben ter Riet, MD PhD, Amsterdam
> 

Here is one way to accomplish this:


. l , noobs

  +-------------------+
  | tp   fp   fn   tn |
  |-------------------|
  |  1    2    3    4 |
  +-------------------+

. xpose, clear varname

. expand v1
(6 observations created)

. sort v

. rename _v gold

. mark v2 if gold =="tp" | gold == "fn"

. l , noobs

  +----------------+
  | v1   gold   v2 |
  |----------------|
  |  1     tp    1 |
  |  2     fp    0 |
  |  2     fp    0 |
  |  3     fn    1 |
  |  3     fn    1 |
  |----------------|
  |  3     fn    1 |
  |  4     tn    0 |
  |  4     tn    0 |
  |  4     tn    0 |
  |  4     tn    0 |
  +----------------+


Keep in mind that -xpose, clear- will drop any string variables.

Hope this helps,
Scott



*
*   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/



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