rolling PCA and saving the proprtion of total variance

For questions regarding the import, export and manipulation of data in EViews, including graphing and basic statistics.

Moderators: EViews Gareth, EViews Jason, EViews Steve, EViews Moderator

wolly77
Posts: 32
Joined: Mon Oct 05, 2009 4:28 am

rolling PCA and saving the proprtion of total variance

Postby wolly77 » Sun Aug 04, 2013 1:10 pm

Dear guys,

I would like to perform the principal component analysis in a dynamic manner. The aim is to save the proportion of total variance accounted for by each principal components using a rolling PCA in a vector. Any idea how this can be done? Thank you in advance.

I attache the code used:

' run rolling pca

' set window size
!window = 61

' set step size
!step = 1

' get size of workfile
!length = @obsrange

' declare group for pca
group x CHN_BM COL_BM CZE_BM HKG_BM HUN_BM IND_BM ISR_BM MAL_BM MEX_BM PAK_BM PER_BM PHI_BM POL_BM SAF_BM SNG_BM TAW_BM THA_BM TUR_BM USA_BM CHI_BM BRZ_BM ARG_BM

'calculate number of rolls
!nrolls = @round((!length-!window)/!step)

'variable keeping track of how many rolls we've done
!j=0

' move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1

' set sample to estimation period
smpl @first+!i-1 @first+!i+!window-2

' store first eigenvalue of PCA in PC1
x.pcomp(n=1)

Return to “Data Manipulation”

Who is online

Users browsing this forum: No registered users and 45 guests