Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: data management


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: Re: data management
Date   Sun, 19 Apr 2009 11:28:42 +0200

<>

This is an attempt to implement what you want. CHeck carefully whether it does what you want when applied to your real dataset. In particular, the loop could conceivably run from 1 to any number, I cannot infer it from your dataset conclusively...

*****
clear*

input ID Time1m1 Time1m2 Time1m3 Time2m1 Time2m2 Time2m3 Time3m1 Time3m2 Time3m3
2018 1 2 1 1 1 1 1 1 2
2020 . . . . . . . . .
2023 . . . . . . . . .
end

compress
list, noobs

reshape long Time1 Time2 Time3, i( ID )  string

drop _j

forv i=1/3{
rename Time`i' m`i'
}

egen float aux = seq(), from(1) to(3) block(1)
egen id=concat(ID aux)
drop ID
drop aux
destring id, gen(ID)
drop id
order ID
l
*****



HTH
Martin
_______________________
----- Original Message ----- From: "Shubhabrata Mukherjee" <joy_stat@yahoo.com>
To: "stata forum" <statalist@hsphsun2.harvard.edu>
Sent: Sunday, April 19, 2009 4:06 AM
Subject: st: data management


Hi,

 I have a dataset of the form:

Time1 Time2 Time3
                   m1  m2  m3             m1 m2 m3         m1  m2  m3
ID

2018 1 2 1 1 1 1 1 1 2

2020 ............................................................................

2023 ..........................................................................

.....................................


and I want my data to look like this:

ID             m1         m2       m3

20181         1           2          1
20182         1           1          1
20183         1           1          2

20201       .............................
20202       .....................
20203

20231
20232
20233
........................................

and I was wondering what would be the best way to accomplish this? Thanks, Joey



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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