Skip to content
Back to formatted view

Raw Message

Message-ID: <50648D02.4020902@gmail.com>
Date: 2012-09-27T17:29:38Z
From: Duncan Murdoch
Subject: equivalent of Stata "by construct"
In-Reply-To: <76D03718A3233B4C8CC236C169B535B5A23DE41109@AUSP01VMBX08.collaborationhost.net>

On 27/09/2012 12:13 PM, Pradipto Banerjee wrote:
> I am evaluating a switch from Stata to R. I don't need to extensive Statistical methods, but the main reason I am exploring the switch is the coding flexibility in R (e.g. Stata does not support linear/quadratic programming). I have been going over the R syntax and I had a quick question:
>
> In Stata, one has a very useful construction called "by", e.g.
>
> by month signal: gen xxx = myfunction(yyy zzz) if cond1==cond2
>
> Similarly, in SAS, one can write
>
> by monthn signal;
> if cond1=cond2 then xxx = myfunction(yyy zzz);
> run;
>
>
> I looked at a lot of R tutorials, but I haven't come across the equivalent of the Stata or SAS "by" construct in R?

There's a by() function, and also the more general tapply().  There are 
also contributed packages with related functions, e.g. the sparseby() 
function in the reshape package.  I believe the reshape2 package has the 
same functionality, but I forget what function does it.

Duncan Murdoch