My table looks (simplified) like this:
| countrycode | year | dummy | Value
| "AUS" | 2008 | 1 | -3
| "AUS" | 2009 | 0 | -2
| "BEL" | 2008 | 0 | -5
| "BEL" | 2009 | 1 | -1
| "BEL" | 2010 | 1 | -2
| "BEL" | 2011 | 1 | -1
| "CAN" | 2008 | 0 | -2
| "CAN" | 2009 | 0 | -5
| "CAN" | 2010 | 1 | 2
| "CAN" | 2011 | 0 | -4
And I would like to get the Mean of the Values grouped by countrycode, like that:
| countrycode | year | dummy | Value | Mean
| "AUS" | 2008 | 1 | -3 | -3
| "AUS" | 2009 | 0 | -2 | -3
| "BEL" | 2008 | 0 | -5 | -1,333
| "BEL" | 2009 | 1 | -1 | -1,333
| "BEL" | 2010 | 1 | -2 | -1,333
| "BEL" | 2011 | 1 | -1 | -1,333
| "CAN" | 2008 | 1 | -2 | -0,5
| "CAN" | 2009 | 0 | -5 | -0,5
| "CAN" | 2010 | 1 | 1 | -0,5
| "CAN" | 2011 | 0 | -4 | -0,5
My question is how can I create a new column for mean from another column that is filtered after a dummy variable?