s-news
[Top] [All Lists]

Re: STATA "collapse" function

To: "Roberts, J. Kyle" <jkrobert@bcm.tmc.edu>
Subject: Re: STATA "collapse" function
From: Chuck Cleland <ccleland@optonline.net>
Date: Wed, 25 Oct 2006 11:56:47 -0400
Cc: s-news@lists.biostat.wustl.edu
In-reply-to: <3FC0430478C30B4A9AF0AFF7863418F130EEDA@BCMEVS6.ad.bcm.edu>
References: <3FC0430478C30B4A9AF0AFF7863418F130EEDA@BCMEVS6.ad.bcm.edu>
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)
Roberts, J. Kyle wrote:
>  
> Dear All,
> 
> I am looking for a function in S-PLUS that works like "collapse" in STATA.  
> Specifically, I am trying to create some level-2 and level-3 datasets for use 
> in HLM from a single dataset that I analyzed as a 3-level model in S-PLUS.  I 
> tried collapse.groupedData, but I'm not getting exactly what I want.
> In STATA, the function might look like:
> 
> collapse (mean)  meanses size sector pracad disclim himinty, by(id)

Have a look at aggregate().  Something like:

aggregate(mydf, by = "id", FUN = mean)

where mydf is a data frame with the id variable and the variables to be
collapsed (aggregated) using the mean function.

> Thanks,
> Kyle
> 
> ***************************************
> J. Kyle Roberts, Ph.D.
> Baylor College of Medicine
> Center for Educational Outreach
> One Baylor Plaza, MS:  BCM411
> Houston, TX   77030-3411
> 713-798-6672 - 713-798-8201 Fax
> jkrobert@bcm.edu
> ***************************************
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

-- 
Chuck Cleland, Ph.D.
NDRI, Inc.
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

<Prev in Thread] Current Thread [Next in Thread>