Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Matrix? Stack? Reshape? Xpose?


From   "David Harrison" <[email protected]>
To   <[email protected]>
Subject   st: RE: Matrix? Stack? Reshape? Xpose?
Date   Thu, 22 Jun 2006 17:37:52 +0100

Wow, tougher than it looks at first, but how's this...

David

. list

     +----------------------------+
     | id   apple   pear   orange |
     |----------------------------|
  1. |  1       2      3        1 |
  2. |  2       1      2        3 |
  3. |  3       2      2        3 |
  4. |  4       3      1        3 |
  5. |  5       3      1        1 |
     +----------------------------+

. drop id

. xpose, clear v

. list

     +-----------------------------------+
     | v1   v2   v3   v4   v5   _varname |
     |-----------------------------------|
  1. |  2    1    2    3    3      apple |
  2. |  3    2    2    1    1       pear |
  3. |  1    3    3    3    1     orange |
     +-----------------------------------+

. forvalues i=1/3 {
  2. egen tot`i' = anycount(v*), v(`i')
  3. }

. drop v*

. list

     +-------------------------------+
     | _varname   tot1   tot2   tot3 |
     |-------------------------------|
  1. |    apple      1      2      2 |
  2. |     pear      2      2      1 |
  3. |   orange      2      0      3 |
     +-------------------------------+ 

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of buddyb
Sent: 22 June 2006 17:11
To: [email protected]
Subject: st: Matrix? Stack? Reshape? Xpose?

Maybe let me explain what I need like this...

Currently I have 5 respondents and 3 variables (apple, pear, oarnge)
coded as 1 2 3 .  My data set looks like
this:
           
      ID       apple     pear      orange
      1           2       3          1
      2           1       2          3
      3           2       2          3
      4           3       1          3
      5           3       1          1


What I want to do is to sort of transpose this so that I would get the
following data table so that it adds up how many 1s 2s and 3s that each
of my variables (apple, pear and oarnge) received:

                   1        2        3
          
         apple     1        2        2
         pear      2        2        1
         orange    2        0        3


Any ideas on what this is called or how to do it?

Thanks, Buddy

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

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