I am new to this website and to R language and this is my first question here :)
I am analyzing a data set of US people's salary in different years and different states (30 in total labeled as 1, 2, ..., 30). The starting year are all the same (1970) but the ending years vary (from 1990 to 2000). For each state, I wish to find the difference between the salary in the ending year and that in the starting year. I wrote the following but it does not work:
for (i in 1:30) {
salarygrowth <- function(salary[state == "i", time == max(1990:2000, na.rm=FALSE)], salary[state == "i", time == 1970]) {
salary[state == "i", time == max(1990:2000, na.rm=FALSE)] - salary[state == "i", time == 1970]}
}
How could I fix and improve it so that I could the desired salary growth for each state with the year provided. Thanks so much in advance!
As required, the following is some data:
time state salary
1970 1 27890
1971 1 28800
1972 1 31257
1973 1 32846
...
1995 1 58934
1970 2 26783
1971 2 28987
...
1997 2 67998
1970 3 21349
...
1992 3 56212
...
2000 30 67876