Hello everyone,

I have a dataset which includes the first three variables from the demo
data below (year, id and var). I need to create the new variable ans as
follows

If var=1, then for each year (where var=1), i need to create a new dummy
ans which takes the value of 1 for all corresponding id's where an instance
of one was recorded. Sample data with the output is shown below.

    year    id var ans
[1,] 2010  1   1   1
[2,] 2010  2   0   0
[3,] 2010  1   0   1
[4,] 2010  1   0   1
[5,] 2011  2   1   1
[6,] 2011  2   0   1
[7,] 2011  1   0   0
[8,] 2011  1   0   0

Any help on how to achieve this is much appreciated.

Thanks
Anup

	[[alternative HTML version deleted]]

