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

Re: st: Organizing data file - Inverse of separate command


From   Philip Ryan <[email protected]>
To   [email protected]
Subject   Re: st: Organizing data file - Inverse of separate command
Date   Tue, 20 Sep 2005 18:14:43 +0930

Things would be simpler if your variable names had the sub-observation index (you call this "id", with values 1 and 7) as the last character in the name, rather than embedded within the name. If that were the case then a simple -reshape- would get you there:

. rename specific7_1 specific1_7

. rename specific7_2 specific2_7

. rename specific1_2 specific2_1

. reshape long specific1_ specific2_ , i(subj) j(id)

. list, clean

subj id com1 com2 specific1_ specific2_
1. 1 1 2 2 1 2
2. 1 7 2 2 5 6
3. 2 1 3 4 5 1
4. 2 7 3 4 2 1

Notes:

1. a simple call to -renvars- [Weesie & Cox STB-60; -findit renvars- ] could get rid of the unwanted "_" suffix on the specific.. variables in the long data set.

2. if there were a great many more than 4 variables of the form: specificX_Y in your real data set, then presumably you could set up a -foreach- loop and reverse the order of X and Y in the variable names using extended local macro functions. Whether this was worth the effort would depend on just how many -rename- commands you needed to write.


Phil



At 09:06 AM 20/09/2005 +0200, you wrote:

Hi all,

I'm looking for a simple command or do file in order to organize a datafile

The actual datafile looks like :
Subj    com1 com2   specific1_1 specific7_1 specific1_2 specific7_2
1       2    2      1           5           2           6
2       3    4      5           2           1           1

I'd like to build up the following file
Subj    com1 com2   id      specific1 specific2
1       2    2      1       1           2
1       2    2      7       5           6
2       3    4      1       5           1
2       3    4      7       2           1

It can be done command by command. But I'm wondering if there is an adhoc
command or do file
Best regards
Naji


*
*   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/
Philip Ryan
Associate Professor,
Department of Public Health
Associate Dean (Information Technology)
Head, Data Management & Analysis Centre
Faculty of Health Sciences
University of Adelaide 5005
South Australia
tel 61 8 8303 3570
fax 61 8 8223 4075
http://www.public-health.adelaide.edu.au/
CRICOS Provider Number 00123M
-----------------------------------------------------------
This email message is intended only for the addressee(s)
and contains information that may be confidential and/or
copyright. If you are not the intended recipient please
notify the sender by reply email and immediately delete
this email. Use, disclosure or reproduction of this email
by anyone other than the intended recipient(s) is strictly
prohibited. No representation is made that this email or
any attachments are free of viruses. Virus scanning is
recommended and is the responsibility of the recipient.

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