Re: [R] Taking a lead in panel data
I have tried the diff and lag function. I have given an example below. Diff gives me a$var2.shift. I want a$var2.noshift, i.e. var^(t+2)-var^(t) should stay in the row with year=t. Diff shifts it to the t+2 row. a - data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA)) colnames(a) - c(firm,year,var) a - pdata.frame(a) a$var2.shift - diff(a$var, lag=2, difference=1) a$var2.noshift - c(NA, 13,-22,NA, NA,NA, 0, NA, NA, NA) a firm year var var2.shift var2.noshift 2-20052 2005 NA NA NA 2-20062 2006 10 NA 13 2-20072 2007 34 NA -22 2-20082 2008 23 13 NA 2-20092 2009 12-22 NA 3-20043 2004 23 NA NA 3-20053 2005 45 NA0 3-20063 2006 NA NA NA 3-20073 2007 45 0 NA 3-20083 2008 NA NA NA On Tue, May 8, 2012 at 6:21 PM, Liviu Andronic landronim...@gmail.comwrote: On Tue, May 8, 2012 at 12:14 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: I have checked that. It allows me to get the t-1, t-2 value but not the t+1 value. Is there any other way of achieving this other than using the plm package? It would be easier to help if you provided a minimal reproducible example, as requested in the posting guide. Have you tried diff(x, lag = -1, ...) or lag(x, k = -1, ...) Perhaps this does what you want. Regards Liviu -- Apoorva Gupta Consultant National Institute of Public Finance and Policy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taking a lead in panel data
I have checked that. It allows me to get the t-1, t-2 value but not the t+1 value. Is there any other way of achieving this other than using the plm package? On Mon, May 7, 2012 at 8:27 PM, Liviu Andronic landronim...@gmail.comwrote: On Mon, May 7, 2012 at 3:21 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: Dear R users, I am working with panel data and I want the difference of a variable with its t+1 value. Could you tell me if such a function exists in the plm package? Perhaps diff() or lag(). See the plm vignette. Liviu -- Apoorva Gupta Consultant National Institute of Public Finance and Policy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taking a lead in panel data
On Tue, May 8, 2012 at 12:14 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: I have checked that. It allows me to get the t-1, t-2 value but not the t+1 value. Is there any other way of achieving this other than using the plm package? It would be easier to help if you provided a minimal reproducible example, as requested in the posting guide. Have you tried diff(x, lag = -1, ...) or lag(x, k = -1, ...) Perhaps this does what you want. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Taking a lead in panel data
Dear R users, I am working with panel data and I want the difference of a variable with its t+1 value. For example, I have a data frame as below. a - data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA)) colnames(a) - c(firm,year,var) I want the output to be as follows. b - data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA),c(10,34,23,12,NA,45, NA, 45, NA, NA)) colnames(b) - c(firm,year,var,var.lead) b firm year var var.lead 1 2 2005 NA 10 2 2 2006 10 34 3 2 2007 34 23 4 2 2008 23 12 5 2 2009 12 NA 6 3 2004 23 45 7 3 2005 45 NA 8 3 2006 NA 45 9 3 2007 45 NA 103 2008 NA NA Could you tell me if such a function exists in the plm package? Thank you -- Apoorva Gupta Consultant National Institute of Public Finance and Policy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taking a lead in panel data
On Mon, May 7, 2012 at 3:21 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: Dear R users, I am working with panel data and I want the difference of a variable with its t+1 value. Could you tell me if such a function exists in the plm package? Perhaps diff() or lag(). See the plm vignette. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.