Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

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

From   Tiffany Duren <>
Subject   Re: st: Question about data management - how to combine 2 rows of data
Date   Thu, 1 Mar 2012 12:21:33 -0500


I'm new to posting, and my idea is probably a simplistic way, compared to other responses, but here's what I have done before with a similar medication file.

If the Day 1 is duplicates for all variables for all ids, then you could first do a "duplicates list"  command to get a total count of duplicates for all variables.  Then, enter "duplicates drop" as it will drop all duplicates where every single variable matches.

After getting rid of the duplicates, I'd separate this spreadsheet into 2 spreadsheets (one morning, and one afternoon).  After checking for duplicates again and fixing your columns, you can then combine the data by matching on subid and date or day.


Tiffany Duren
Sr. Research Program Coordinator, M.S., CCRP

Johns Hopkins University, School of Medicine
Behavioral Pharmacology Research Unit
Johns Hopkins Bayview Medical Center
5510 Nathan Shock Drive
Baltimore, MD 21224

WARNING:  E-mail sent over the Internet is not secure.  Information sent by e-mail may not remain confidential.
DISCLAIMER:  This e-mail is intended only for the individual to whom it is addressed.  It may be used only in accordance with applicable laws.  If you received this e-mail by mistake, notify the sender and destroy the e-mail.

On Mar 1, 2012, at 11:00 AM, Maria Cecilia Vieira da Silva wrote:

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

*   For searches and help try:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index