s-news
[Top] [All Lists]

Re: STATA "collapse" function

To: s-news@lists.biostat.wustl.edu
Subject: Re: STATA "collapse" function
From: Chuck Cleland <ccleland@optonline.net>
Date: Wed, 25 Oct 2006 11:59:24 -0400
Cc: "Roberts, J. Kyle" <jkrobert@bcm.tmc.edu>
In-reply-to: <453F893F.6060707@optonline.net>
References: <3FC0430478C30B4A9AF0AFF7863418F130EEDA@BCMEVS6.ad.bcm.edu> <453F893F.6060707@optonline.net>
User-agent: Thunderbird 1.5.0.7 (Windows/20060909)
Chuck Cleland wrote:
> 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)

I should read the help page myself ...

aggregate(mydf, list(id=mydf$id), 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>