/* Dimension Indexing */ new; cls; nn=10; dim=3; print/rz dimindex(nn,dim); /* ** dimindex.txt - Dimension Indexing. ** (C) Copyright 2005 Yosuke Amijima. All Rights Reserved. ** ** Purpose: Gets index numbers for given dimension in a very easy way. ** ** Format: y=dimindex(nn,dim); ** ** Input: nn scalar, max number of index (1,2,3,...,nn) ** ** dim scalar, dimension (1,...,dim) ** ** ** Output: y 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 dimindex(nn,dim); local x,b,n,z,y; /* 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 */ retp(y); endp;