Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

st: RE: Question about data management - how to combine 2 rows of data


From   <Jean-Francois.Bertrand@fin.gc.ca>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Question about data management - how to combine 2 rows of data
Date   Thu, 1 Mar 2012 11:18:04 -0500

Hello,

The general approach I would use (might not be the most efficient way) would be:

I assume "missing" is a "." so that once sorted it will be the last observation for day 1.

bysort id day pill_morning: replace pill_afternoon = pill_afternoon [_n+1] if day == 1 
...
bysort id day pill_morning: drop if _n == 2

Jean-François Bertrand


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Maria Cecilia Vieira da Silva
Sent: March 1, 2012 11:00 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: Question about data management - how to combine 2 rows of data

Hello,
I have a problem with my panel data. Day 1 is duplicate for all the ids. The first "day 1" observation refers to the morning variables and the second 'day 1" observation refers to the afternoon variables. The rest of the days are fine - they are listed just once in the panel.
I would like to combine the rows for "day 1" and keep only 1 observation, so that I have information on the morning and afternoon variables combined in one row and would like to keep the variables that are invariable to "day".
Any suggestions?
I thought about using collapse, but it would change the names of the variables that are valid for the rest of the data set.  
Thanks,
M.Cecilia

id            day         pill_morning       pill_afternoon   pain_morning    pain_afternoon        sex
1              1              1                              missing                 5                              missing     M
1              1              missing                 3                              missing                 9                   M
1              2              1                              3                              1                              2            M
1              3              3                              5                              0                              1               M
2              1              2                              missing                 8                              missing     F
2              1              missing                 1                              missing                     3                F
2              2              0                              1                              0                              3              F
2              3              1                              0                              2                              0            F
*
*   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   |   Site index