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

RE: st: Formatting Data (collapse/transpose)


From   "Svend Juul" <[email protected]>
To   <[email protected]>
Subject   RE: st: Formatting Data (collapse/transpose)
Date   Mon, 25 Jul 2005 11:40:34 +0200

Kelly,

You want to -reshape- your data, but the fact that Var1 is string
complicates things a little bit. Here is how I did it:

----------------------------------------
. clear
. input str7 date str1 abcd x
          date       abcd          x
  1. "1/1/05" "a" 12
  2. "1/1/05" "b" 11
  3. "1/1/05" "c" 19
  4. "1/1/05" "d" 9
  5. "1/2/05" "a" 10
  6. "1/2/05" "b" 14
  7. "1/2/05" "c" 21
  8. "1/2/05" "d" 12
  9. "1/30/05" "a" 12
 10. "1/30/05" "b" 1
 11. "1/30/05" "c" 19
 12. "1/30/05" "d" 31
 13. end

. encode abcd , generate(z)
. drop abcd
. reshape wide x , i(date) j(z)
. rename x1 a
. rename x2 b
. rename x3 c
. rename x4 d
. list

     +-----------------------------+
     |    date    a    b    c    d |
     |-----------------------------|
  1. |  1/1/05   12   11   19    9 |
  2. |  1/2/05   10   14   21   12 |
  3. | 1/30/05   12    1   19   31 |
     +-----------------------------+
--------------------------------------------------

Hope this helps,

Svend
__________________________________________

Svend Juul
Institut for Folkesundhed, Afdeling for Epidemiologi
(Institute of Public Health, Department of Epidemiology)
Vennelyst Boulevard 6
DK-8000  Aarhus C, Denmark
Phone: +45 8942 6090
Home:  +45 8693 7796
Email: [email protected]
__________________________________________ 

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