computing montly averages when time series observations are irregural

1 visualizzazione (ultimi 30 giorni)
Dear all,
I have the following problem
Let
A ={
'02/11/08' [0.2150] [429.5674] [ 100] [2.2678e+04]
'30/11/08' [0.2117] [463.1360] [ 100] [2.4383e+04]
'28/12/08' [0.2209] [436.6316] [ 100] [2.3148e+04]
'25/01/09' [0.2212] [441.5430] [ 100] [2.2987e+04]
'22/02/09' [0.2201] [453.7015] [ 100] [2.3675e+04]
'22/03/09' [0.2185] [461.3925] [ 100] [2.3680e+04]
'19/04/09' [0.2104] [486.4095] [ 100] [2.5367e+04]
'17/05/09' [0.2162] [451.4833] [ 100] [2.3986e+04]
'14/06/09' [0.2158] [475.8620] [ 100] [2.4245e+04]
'12/07/09' [0.2211] [449.4574] [ 100] [2.2766e+04]
'09/08/09' [0.2221] [456.2507] [ 100] [2.2523e+04]
'06/09/09' [0.2175] [472.2659] [ 100] [2.3593e+04]
'04/10/09' [0.2182] [479.3408] [ 100] [2.4359e+04]
'01/11/09' [0.2286] [442.6719] [ 100] [2.1490e+04]
'29/11/09' [0.2211] [481.4548] [ 100] [2.4054e+04]
'27/12/09' [0.2259] [468.2757] [ 100] [2.3037e+04]
'31/01/10' [0.2300] [461.5581] [ 100] [2.2050e+04]
'28/02/10' [0.2259] [487.6257] [ 100] [2.3293e+04]
'28/03/10' [0.2200] [529.8777] [ 100] [2.5493e+04]
'25/04/10' [0.2315] [433.3039] [ 100] [2.0387e+04]
'23/05/10' [0.2274] [500.8603] [ 100] [2.4019e+04]
}
As you can see from the first column I have irregular time series observations. Each observation can represent a 4-week or a 5-week or a 6-week average. For example the observation [0.2117] which is the second value of the second column is the average of the values that have been recorded between ‘03/11/08' and '30/11/08' In order to be able to analyze econometrically these data and run my regressions I need to obtain regular time series observations. So I need to convert these values to monthly averages and have something like
Let A ={
'11/08' [mon. average] [mon. average] [mon. average]
'12/08' [mon. average] [mon. average] [mon. average]
'01/09' [mon. average] [mon. average] [mon. average]
'02/09' [mon. average] [mon. average] [mon. average]
'03/09' [mon. average] [mon. average] [mon. average]
'04/09' [mon. average] [mon. average] [mon. average]
'05/09' [mon. average] [mon. average] [mon. average]
'06/09' [mon. average] [mon. average] [mon. average]
'07/09' [mon. average] [mon. average] [mon. average]
'08/09' [mon. average] [mon. average] [mon. average]
'09/09' [mon. average] [mon. average] [mon. average]
'10/09' [mon. average] [mon. average] [mon. average]
'11/09' [mon. average] [mon. average] [mon. average]
'12/09' [mon. average] [mon. average] [mon. average]
}
Could interpolation be a solution to this problem? I would be grateful if you could provide some code.
cheers
  3 Commenti
antonet
antonet il 29 Lug 2012
Modificato: antonet il 29 Lug 2012
Hi imager! yes as you can see there is overlapping across the dates as each value is the average of the values that have been observed 4 weeks (or 5 weeks or 6 weeks) back. Advice me what is the best approach to calculate the monthly averages. PLease ask me if you require further information

Accedi per commentare.

Risposta accettata

per isakson
per isakson il 28 Lug 2012
Modificato: per isakson il 28 Lug 2012
Hint:
  • vec = datevec( A{:,1}, 'dd/mm/yy' )
  • out = accumarray( vec(:,2), A(something), [], @mean )
Better
vec = datevec( char(A{:,1}), 'dd/mm/yy' );
out = accumarray( vec(:,2:3), transpose([A{:,2}]), [], @mean );
This returns the means of the values of each month respectively. There is a value for each month. Is that what you want?

Più risposte (0)

Tag

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by