I'm trying to create a new variable in R containing the initial values of another variable (crime) based on groups (countries) considering the initial period of time observable per group (on panel data framework), my current data looks like this:
| country | year | Crime |
|---|---|---|
| Albania | 2016 | 2.7369478 |
| Albania | 2017 | 2.0109779 |
| Argentina | 2002 | 9.474084 |
| Argentina | 2003 | 7.7898825 |
| Argentina | 2004 | 6.0739941 |
And I want it to look like this:
| country | year | Crime | Initial_Crime |
|---|---|---|---|
| Albania | 2016 | 2.7369478 | 2.7369478 |
| Albania | 2017 | 2.0109779 | 2.7369478 |
| Argentina | 2002 | 9.474084 | 9.474084 |
| Argentina | 2003 | 7.7898825 | 9.474084 |
| Argentina | 2004 | 6.0739941 | 9.474084 |
I saw that ddply could make it work this way, but the problem is that it is not longer supported by the latest R updates.
Thank you in advance.