/* Improved Dimension Indexing */ new; cls; nn=10; dim=3; print/rz dimindex1(nn,dim); /* ** dimindex1.txt - Dimension Indexing by re-partitioning the same index numbers ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Gets improved index numbers for given dimension in a very easy way. ** ** Format: x=dimindex1(nn,dim); ** ** Input: nn scalar, max number of index (1,2,3,...,nn) ** ** dim scalar, dimension (1,...,dim) ** ** ** Output: x matrix , (nn^dim) x (dim) of resulting index matrix ** ** Notice: It takes lots of memory to run. Light version of GAUSS will not work in most cases. ** Here, index starts from 1 as in GAUSS. ** ** This algorithm can be easily implemented in EXCEL, Stata, etc... No more hustle on quasi-random sequences. */ proc dimindex1(nn,dim); local x,b,n,z,y,j; /* convert x(base 10) to y(base b) */ x=seqa(1,1,nn^dim-1); b=nn; n=maxc(log(x)/log(b))+1; z=reshape(b,n,rows(x)); y=rev(recserrc(x,z))'; /* adjustments */ y=y+1; /* shift all elements by 1 */ y=ones(1,dim)|y; /* insert 1's at the 1st row */ /* re-indexing each number */ x=zeros(nn^dim,dim); j=1; do while j<=dim; x[.,j]=rerankindx(y[.,j]); j=j+1; endo; retp(x); endp; proc rerankindx(x); local k,y,i,j; k=1; y=zeros(rows(x),cols(x)); j=minc(x); do while j<=maxc(x); i=1; do while i<=rows(x); if x[i]==j; y[i]=k; k=k+1; endif; i=i+1; endo; j=j+1; endo; retp(y); endp;