How to convert quarterly data into monthly and merge together
조회 수: 32 (최근 30일)
이전 댓글 표시
Dear all, I have a quarterly data and some monthly data. I want to convert the quarterly into a monthly format where the new data will only have the Q1(MARCH) Q2(JUNE) Q3(SEPTEMBER) AND Q4( DECEMBER) will only have values while the remaining months will be filled with NA.
For example,
Quarterly
2000q1. 12
2000q2. 14
2000q3. 18
2000q4. 22
New data Monthly 2000m1 Na 2000m2. Na 2000m3. 12 2000m4. Na 2000m5. Na 2000m6. 14 2000m7. Na 2000m8. Na 20000m9 18 2000m10. Na 2000m11. Na 2000m12. 22 After which I will merge the data together and the end result will have quarterly data repeated for the monthly NA.
댓글 수: 0
답변 (1개)
dpb
2023년 10월 15일
편집: dpb
2023년 10월 15일
댓글 수: 8
dpb
2023년 10월 16일
You'll have to have exactly as many values of GDP to assign as the number of elements in the indexing vector you create. The index I used of
3:3:12
has only four values in it to match the values in the original question; didn't have any more at the time.
Try
Date=[datetime(2005,1,1):calmonths(1):datetime(2022,3,31)].';
TtQ=timetable(Date,nan(size(Date)),'VariableNames',{'GDP'});
TtQ.GDP(3:3:end)=GDP.GDP; % use whatever is the column variable in the table
It may be off by one; just fix up the index array to match whatever the length is. Or, alternatively, you can create a logical indexing vector by matching the timestamp in the GDP timeseries as
TtQ.GDP(TtQ.Date==GDP.Time)=GDP.GDP; % use what are the column variables in the table
I can't see your original data so am having to guess about what the timeseries itself is named as well as the timestamp and data column names; use whatever they really are. There's no reason to need array2table, just reference the variable out of the timetable/timeseries.
참고 항목
카테고리
Help Center 및 File Exchange에서 Time Series Events에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!