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

Re: st: data management question


From   David Airey <[email protected]>
To   [email protected]
Subject   Re: st: data management question
Date   Thu, 15 May 2003 12:22:28 -0500

Following Ulrich's advice, I got what I wanted.

Thanks so much!

-Dave


. list

+--------------------------------------+
| marker group_1 group_2 group_3 |
|--------------------------------------|
1. | 1 aa aa bb |
2. | 2 aa aa bb |
3. | 3 aa bb bb |
+--------------------------------------+

. ren marker m

. reshape long group_, i(m) j(index)
(note: j = 1 2 3)

Data wide -> long
------------------------------------------------------------------------ -----
Number of obs. 3 -> 9
Number of variables 4 -> 3
j variable (3 values) -> index
xij variables:
group_1 group_2 group_3 -> group_
------------------------------------------------------------------------ -----

. list

+--------------------+
| m index group_ |
|--------------------|
1. | 1 1 aa |
2. | 1 2 aa |
3. | 1 3 bb |
4. | 2 1 aa |
5. | 2 2 aa |
|--------------------|
6. | 2 3 bb |
7. | 3 1 aa |
8. | 3 2 bb |
9. | 3 3 bb |
+--------------------+

. ren group_ marker

. reshape wide marker, j(m) i(index)
(note: j = 1 2 3)

Data long -> wide
------------------------------------------------------------------------ -----
Number of obs. 9 -> 3
Number of variables 3 -> 4
j variable (3 values) m -> (dropped)
xij variables:
marker -> marker1 marker2 marker3
------------------------------------------------------------------------ -----

. list

+-------------------------------------+
| index marker1 marker2 marker3 |
|-------------------------------------|
1. | 1 aa aa aa |
2. | 2 aa aa bb |
3. | 3 bb bb bb |
+-------------------------------------+

. ren index group

. sort group

. save ll, replace
file ll.dta saved

. clear

. use group

. sort group

. list

+-------------+
| group var |
|-------------|
1. | 1 2 |
2. | 1 3 |
3. | 1 2 |
4. | 2 5 |
5. | 2 4 |
|-------------|
6. | 3 3 |
7. | 3 4 |
8. | 3 5 |
9. | 3 5 |
+-------------+

. merge group using ll

. list

+----------------------------------------------------+
| group var marker1 marker2 marker3 _merge |
|----------------------------------------------------|
1. | 1 2 aa aa aa 3 |
2. | 1 3 aa aa aa 3 |
3. | 1 2 aa aa aa 3 |
4. | 2 5 aa aa bb 3 |
5. | 2 4 aa aa bb 3 |
|----------------------------------------------------|
6. | 3 3 bb bb bb 3 |
7. | 3 4 bb bb bb 3 |
8. | 3 5 bb bb bb 3 |
9. | 3 5 bb bb bb 3 |
+----------------------------------------------------+

.

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