Suppose the data is:
data <- structure(list(country = c("Poland", "Poland", "Poland", "Poland",
"Poland", "Poland", "Portugal", "Portugal", "Portugal", "Portugal",
"Portugal", "Portugal", "Spain", "Spain", "Spain", "Spain", "Spain",
"Spain"), Code = c("POL", "POL", "POL", "POL", "POL", "POL",
"PRT", "PRT", "PRT", "PRT", "PRT", "PRT", "ESP", "ESP", "ESP",
"ESP", "ESP", "ESP"), year = c(1950, 1951, 1952, 1953, 1954,
1955, 1950, 1951, 1952, 1953, 1954, 1955, 1950, 1951, 1952, 1953,
1954, 1955), IV = c(3, 3, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1)), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L), class = "data.frame")
How to difference IV values within each panel (country)? In other words, I want to substract IV values for the year of 1951 from 1950; 1952-1951; 1953-1952; 1954-1953; 1955-1954. And so for every country. In the outcome dataset (let's name it 'newdata'), IV value for each year has to show its difference with an IV value from a previous year; 1950 year should be just empty.
Any suggestions, guys? Hope my question is not confusing.
Using
diffinaveperhaps.To eliminate 1950 thereafter, pipe in a
subset.Data: