Dear R users, I have a panel data set (in MS excel) on prices across countries and time country time price 1 "23/11/08" 2 1 "28/12/08" 3 1 "25/01/09" 4 1 "22/02/09" 5 1 "29/03/09" 6 1 "26/04/09" 32 1 "24/05/09" 23 1 "28/06/09" 32 2 "26/10/08" 45 2 "23/11/08" 46 2 "21/12/08" 90 2 "18/01/09" 54 2 "15/02/09" 65 2 "16/03/09" 77 2 "12/04/09" 7 2 "10/05/09" 6 As you can see, 1)the start and end date of the time series for countries 1 and 2 are different. For example, for country 1 the time series begins on "23/11/08" while for country 2 the time series begins on "26-10-2008?. 2)My data on prices are available every 28 days (or equivalently every 4 weeks). So, each observation is a 4-week average. But in some cases I have jumps (35 days or 29 days instead of 28 days). For example from the above table we have such jumps: from "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc My goal is to have a unified sequence of dates across countries. Otherwise I will not be able to do further data/econometric analysis, Unless you have different suggestion, I want to take what I have and calculate monthly average prices and also report how many prices those averages are based on. I suppose that I will still have gaps and may well need to interpolate. Put differently, I want to interpolate the 4-week average prices to monthly average prices. The problem is also the jumps where I have 5 weeks in some cases and I want to find the monthly average of it. I do not want something like country yearmon avg.price freq 1 1 Nov 2008 2 1 2 1 Dec 2008 3 1 3 1 Jan 2009 4 1 4 1 Feb 2009 5 1 5 1 Mar 2009 6 1 6 1 Apr 2009 32 1 7 1 May 2009 23 1 8 1 Jun 2009 32 1 9 2 Oct 2008 45 1 10 2 Nov 2008 46 1 11 2 Dec 2008 90 1 12 2 Jan 2009 54 1 13 2 Feb 2009 65 1 14 2 Mar 2009 77 1 15 2 Apr 2009 7 1 16 2 May 2009 6 1 Please, I would be grateful to you if you could provide the exact code for doing this thank you
stop repeating yourself. and stop asking us to do your work. Try reading the posting guide. Give us an example of the output you DO want. Show us the code you already have. Use the dput function to give us example data to work with. Learn to use the str function so you know what data you are really working with. Ask specific questions. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --------------------------------------------------------------------------- Sent from my phone. Please excuse my brevity. stef salvez <loggyedy at googlemail.com> wrote:>Dear R users, >I have a panel data set (in MS excel) on prices across countries and >time > >country time price > 1 "23/11/08" 2 >1 "28/12/08" 3 >1 "25/01/09" 4 >1 "22/02/09" 5 >1 "29/03/09" 6 >1 "26/04/09" 32 >1 "24/05/09" 23 >1 "28/06/09" 32 >2 "26/10/08" 45 >2 "23/11/08" 46 >2 "21/12/08" 90 >2 "18/01/09" 54 >2 "15/02/09" 65 >2 "16/03/09" 77 >2 "12/04/09" 7 >2 "10/05/09" 6 > > >As you can see, > >1)the start and end date of the time series for countries 1 and 2 are >different. For example, for country 1 the time series begins on >"23/11/08" while for country 2 the time series begins on "26-10-2008?. > >2)My data on prices are available every 28 days (or equivalently every >4 >weeks). So, each observation is a 4-week average. But in some cases I >have jumps (35 days or 29 days instead of >28 days). For example from the above table we have such jumps: from >"28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc > >My goal is to have a unified sequence of dates across countries. >Otherwise I will not be able to do further data/econometric analysis, >Unless you have different suggestion, I want to take what I have and >calculate monthly average prices and also report how many prices those >averages are based on. I suppose that I will still have gaps and may >well need to interpolate. > >Put differently, I want to interpolate the 4-week average prices to >monthly average prices. >The problem is also the jumps where I have 5 weeks in some cases and I >want to find the monthly average of it. > I do not want something like > > country yearmon avg.price freq >1 1 Nov 2008 2 1 >2 1 Dec 2008 3 1 >3 1 Jan 2009 4 1 >4 1 Feb 2009 5 1 >5 1 Mar 2009 6 1 >6 1 Apr 2009 32 1 >7 1 May 2009 23 1 >8 1 Jun 2009 32 1 >9 2 Oct 2008 45 1 >10 2 Nov 2008 46 1 >11 2 Dec 2008 90 1 >12 2 Jan 2009 54 1 >13 2 Feb 2009 65 1 >14 2 Mar 2009 77 1 >15 2 Apr 2009 7 1 >16 2 May 2009 6 1 > > >Please, I would be grateful to you if you could provide the exact code >for doing this > >thank you > >______________________________________________ >R-help at 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.
you are right Jeff and sorry for this I will try to explain what I want. I have the following dataset dat <- data.frame("country" = c(rep(1,4)), "date" = c("23/11/08","28/12/08","25/01/09","22/02/09"), "price" = c(2,3,4,5)) Normally, prices are observed every 4 weeks (28 days). Each observation that it is published is a 4-week average. In some cases, though, I have jumps (35 days-see from "23/11/08" to "28/12/08"). So some prices that are published are 5-week average I want to interpolate the 4-week average prices to monthly prices so as to have dat <- data.frame("country" = c(rep(1,4)), "date" = c("11/08","12/08","01/09","02/09"), "price" = c(3,2,1,4)) where the "new" "price" = c(3,2,1,4) will contain the interpolated prices. So by starting what I have , that is, - "price" = c(2,3,4,5)) -I want to calculate monthly average prices via interpolation. I hope to have been more explicit. thank you and apologies for one more time, On 6/17/12, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:> stop repeating yourself. and stop asking us to do your work. > > Try reading the posting guide. Give us an example of the output you DO want. > Show us the code you already have. Use the dput function to give us example > data to work with. Learn to use the str function so you know what data you > are really working with. Ask specific questions. > --------------------------------------------------------------------------- > Jeff Newmiller The ..... ..... Go Live... > DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go... > Live: OO#.. Dead: OO#.. Playing > Research Engineer (Solar/Batteries O.O#. #.O#. with > /Software/Embedded Controllers) .OO#. .OO#. rocks...1k > --------------------------------------------------------------------------- > > Sent from my phone. Please excuse my brevity. > > > > stef salvez <loggyedy at googlemail.com> wrote: > >>Dear R users, >>I have a panel data set (in MS excel) on prices across countries and >>time >> >>country time price >> 1 "23/11/08" 2 >>1 "28/12/08" 3 >>1 "25/01/09" 4 >>1 "22/02/09" 5 >>1 "29/03/09" 6 >>1 "26/04/09" 32 >>1 "24/05/09" 23 >>1 "28/06/09" 32 >>2 "26/10/08" 45 >>2 "23/11/08" 46 >>2 "21/12/08" 90 >>2 "18/01/09" 54 >>2 "15/02/09" 65 >>2 "16/03/09" 77 >>2 "12/04/09" 7 >>2 "10/05/09" 6 >> >> >>As you can see, >> >>1)the start and end date of the time series for countries 1 and 2 are >>different. For example, for country 1 the time series begins on >>"23/11/08" while for country 2 the time series begins on "26-10-2008?. >> >>2)My data on prices are available every 28 days (or equivalently every >>4 >>weeks). So, each observation is a 4-week average. But in some cases I >>have jumps (35 days or 29 days instead of >>28 days). For example from the above table we have such jumps: from >>"28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc >> >>My goal is to have a unified sequence of dates across countries. >>Otherwise I will not be able to do further data/econometric analysis, >>Unless you have different suggestion, I want to take what I have and >>calculate monthly average prices and also report how many prices those >>averages are based on. I suppose that I will still have gaps and may >>well need to interpolate. >> >>Put differently, I want to interpolate the 4-week average prices to >>monthly average prices. >>The problem is also the jumps where I have 5 weeks in some cases and I >>want to find the monthly average of it. >> I do not want something like >> >> country yearmon avg.price freq >>1 1 Nov 2008 2 1 >>2 1 Dec 2008 3 1 >>3 1 Jan 2009 4 1 >>4 1 Feb 2009 5 1 >>5 1 Mar 2009 6 1 >>6 1 Apr 2009 32 1 >>7 1 May 2009 23 1 >>8 1 Jun 2009 32 1 >>9 2 Oct 2008 45 1 >>10 2 Nov 2008 46 1 >>11 2 Dec 2008 90 1 >>12 2 Jan 2009 54 1 >>13 2 Feb 2009 65 1 >>14 2 Mar 2009 77 1 >>15 2 Apr 2009 7 1 >>16 2 May 2009 6 1 >> >> >>Please, I would be grateful to you if you could provide the exact code >>for doing this >> >>thank you >> >>______________________________________________ >>R-help at 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. > >
or put differently, I want to change the data frequency of the time series to monthly thanks On 6/17/12, stef salvez <loggyedy at googlemail.com> wrote:> you are right Jeff and sorry for this > > I will try to explain what I want. > > I have the following dataset > > dat <- data.frame("country" = c(rep(1,4)), > "date" = c("23/11/08","28/12/08","25/01/09","22/02/09"), > "price" = c(2,3,4,5)) > > Normally, prices are observed every 4 weeks (28 days). Each > observation that it is published is a 4-week average. In some cases, > though, I have jumps (35 days-see from "23/11/08" to "28/12/08"). So > some prices that are published are 5-week average > > I want to interpolate the 4-week average prices to monthly prices > so as to have > > dat <- data.frame("country" = c(rep(1,4)), > "date" = c("11/08","12/08","01/09","02/09"), > "price" = c(3,2,1,4)) > > where the "new" "price" = c(3,2,1,4) will contain the interpolated > prices. So by starting what I have , that is, - "price" = c(2,3,4,5)) > -I want to calculate monthly average prices via interpolation. > > I hope to have been more explicit. > > thank you and apologies for one more time, > > > > > > On 6/17/12, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: >> stop repeating yourself. and stop asking us to do your work. >> >> Try reading the posting guide. Give us an example of the output you DO >> want. >> Show us the code you already have. Use the dput function to give us >> example >> data to work with. Learn to use the str function so you know what data >> you >> are really working with. Ask specific questions. >> --------------------------------------------------------------------------- >> Jeff Newmiller The ..... ..... Go >> Live... >> DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live >> Go... >> Live: OO#.. Dead: OO#.. Playing >> Research Engineer (Solar/Batteries O.O#. #.O#. with >> /Software/Embedded Controllers) .OO#. .OO#. >> rocks...1k >> --------------------------------------------------------------------------- >> >> Sent from my phone. Please excuse my brevity. >> >> >> >> stef salvez <loggyedy at googlemail.com> wrote: >> >>>Dear R users, >>>I have a panel data set (in MS excel) on prices across countries and >>>time >>> >>>country time price >>> 1 "23/11/08" 2 >>>1 "28/12/08" 3 >>>1 "25/01/09" 4 >>>1 "22/02/09" 5 >>>1 "29/03/09" 6 >>>1 "26/04/09" 32 >>>1 "24/05/09" 23 >>>1 "28/06/09" 32 >>>2 "26/10/08" 45 >>>2 "23/11/08" 46 >>>2 "21/12/08" 90 >>>2 "18/01/09" 54 >>>2 "15/02/09" 65 >>>2 "16/03/09" 77 >>>2 "12/04/09" 7 >>>2 "10/05/09" 6 >>> >>> >>>As you can see, >>> >>>1)the start and end date of the time series for countries 1 and 2 are >>>different. For example, for country 1 the time series begins on >>>"23/11/08" while for country 2 the time series begins on "26-10-2008?. >>> >>>2)My data on prices are available every 28 days (or equivalently every >>>4 >>>weeks). So, each observation is a 4-week average. But in some cases I >>>have jumps (35 days or 29 days instead of >>>28 days). For example from the above table we have such jumps: from >>>"28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc >>> >>>My goal is to have a unified sequence of dates across countries. >>>Otherwise I will not be able to do further data/econometric analysis, >>>Unless you have different suggestion, I want to take what I have and >>>calculate monthly average prices and also report how many prices those >>>averages are based on. I suppose that I will still have gaps and may >>>well need to interpolate. >>> >>>Put differently, I want to interpolate the 4-week average prices to >>>monthly average prices. >>>The problem is also the jumps where I have 5 weeks in some cases and I >>>want to find the monthly average of it. >>> I do not want something like >>> >>> country yearmon avg.price freq >>>1 1 Nov 2008 2 1 >>>2 1 Dec 2008 3 1 >>>3 1 Jan 2009 4 1 >>>4 1 Feb 2009 5 1 >>>5 1 Mar 2009 6 1 >>>6 1 Apr 2009 32 1 >>>7 1 May 2009 23 1 >>>8 1 Jun 2009 32 1 >>>9 2 Oct 2008 45 1 >>>10 2 Nov 2008 46 1 >>>11 2 Dec 2008 90 1 >>>12 2 Jan 2009 54 1 >>>13 2 Feb 2009 65 1 >>>14 2 Mar 2009 77 1 >>>15 2 Apr 2009 7 1 >>>16 2 May 2009 6 1 >>> >>> >>>Please, I would be grateful to you if you could provide the exact code >>>for doing this >>> >>>thank you >>> >>>______________________________________________ >>>R-help at 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. >> >> >