[R] Dummy (factor) based on a pair of variables

2009-04-18 Thread Serguei Kaniovski
Dear All! my data is on pairs of countries, i and j, e.g.: y,i,j 1,AUT,BEL 2,AUT,GER 3,BEL,GER I would like to create a dummy (indicator) variable for use in regression (using factor?), such that it takes the value of 1 if the country is in the pair (i.e. EITHER an i-country OR an j-country).

Re: [R] Dummy (factor) based on a pair of variables

2009-04-18 Thread Bernardo Rangel Tura
On Sat, 2009-04-18 at 08:55 +0200, Serguei Kaniovski wrote: Dear All! my data is on pairs of countries, i and j, e.g.: y,i,j 1,AUT,BEL 2,AUT,GER 3,BEL,GER I would like to create a dummy (indicator) variable for use in regression (using factor?), such that it takes the value of 1 if

Re: [R] Dummy (factor) based on a pair of variables

2009-04-18 Thread Serguei Kaniovski
Bernardo: this is not quite what I am looking for, Let the data be: y,i,j 1,AUT,BEL 2,AUT,GER 3,BEL,GER then the dummies sould look like: y,i,j,d_AUT,d_BEL,d_GER 1,AUT,BEL,1,1,0 2,AUT,GER,1,0,1 3,BEL,GER,0,1,1 I can generate the above dummies but can this design be imputed in a reg. model

Re: [R] Dummy (factor) based on a pair of variables

2009-04-18 Thread Jason Morgan
On 2009.04.18 13:52:35, Serguei Kaniovski wrote: Bernardo: this is not quite what I am looking for, Let the data be: y,i,j 1,AUT,BEL 2,AUT,GER 3,BEL,GER then the dummies sould look like: y,i,j,d_AUT,d_BEL,d_GER 1,AUT,BEL,1,1,0 2,AUT,GER,1,0,1 3,BEL,GER,0,1,1 I can generate the

Re: [R] Dummy (factor) based on a pair of variables

2009-04-18 Thread Jason Morgan
On 2009.04.18 15:58:30, Jason Morgan wrote: On 2009.04.18 13:52:35, Serguei Kaniovski wrote: I can generate the above dummies but can this design be imputed in a reg. model directly? Oops, I apologize for not reading the whole question. Can you do the following: lm(y ~

Re: [R] Dummy (factor) based on a pair of variables

2009-04-18 Thread David Winsemius
df - read.table(textConnection(y,i,j + 1,AUT,BEL + 2,AUT,GER + 3,BEL,GER), header=T,sep=,, as.is=T) df y i j 1 1 AUT BEL 2 2 AUT GER 3 3 BEL GER countries - unique(c(df$i,df$j)) countries [1] AUT BEL GER df[countries] - sapply(countries, function(x) df[x] - df$i == x | df$j == x)