[R] Egen and concat
David Winsemius
dwinsemius at comcast.net
Thu May 30 07:15:33 CEST 2013
On May 29, 2013, at 3:10 PM, Daniel Tucker wrote:
> Let me explain what I am planning on doing; some background is
> probably
> necessary and in hindsight the first email doesn't accurately
> describe what
> I am looking to do. I'm trying to run a conditional logit model, but
> I want
> to have a different strata depending on the value of another variable
> if sample==1 I want my strata to be stratida
> if sample==2 I want my strata to be stratidb
> if sample==3 I want my strata to be stratidc
>
> stratida/stratidb/stratidc are NOT variables already in the dataset.
> they represent a string combination of three already present numerical
> variables (year, byregn2, group) and differ for when the variable
> sample is
> ==1,2 or 3. They are different variables for labeling purposes. What
> I am
> looking to do is replicate these in one variable--make one variable
> that is
> the string combination of year, byregn2, and group and then use it
> as my
> strata.
If dfrm is a data.frame with column names: year, byregn2, group then
creating a 4th column named strata:
dfrm$strata <- with( dfrm, paste0(year, byregn2, group) )
If you want tested code, you need to offer actual R objects.
--
David.
>
> On Wed, May 29, 2013 at 1:53 PM, Adams, Jean <jvadams at usgs.gov> wrote:
>
>> You are limiting yourself to getting help from only those people that
>> understand the STATA language. You may improve your chances for a
>> helpful
>> response if you tell us in English what the STATA commands mean.
>>
>> Jean
>>
>>
>> On Wed, May 29, 2013 at 10:37 AM, Daniel Tucker <dtucker9 at u.rochester.edu
>> >wrote:
>>
>>> R list members,
>>>
>>> I am trying to replicate a command script in STATA and find
>>> equivalency in R to the following Stata command:
>>>
>>> egen stratida = concat(year byregn2 group) if sample==1
>>> egen stratidb = concat(year byregn2 group) if sample==2
>>> egen stratidc = concat(year byregn2 group) if sample==3
>>>
>>> Not sure if I should just try to make a for loop and use the paste
>>> operator or if there is somewhere else I should be looking.
>>>
>>>
>>> Thanks,
>>>
>>> Daniel
>>>
David Winsemius, MD
Alameda, CA, USA
More information about the R-help
mailing list