Post date: Sep 12, 2012 7:42:55 PM
ForFiles command in Matrix Algebra
Lets you repeat a command for a series of files that are similarly named, as in "samplk1", "samplk2", "samplk3"
Syntax is ->forfiles <filemask> <command with "$$" used to stand in for file name>
For example, if you have unpacked the 'sampson' dataset so that you have a bunch of files on disk with names like "samplk1", "samplk2", and "samplk3" and want to compute and store the average value of each row for each matrix, you could type:
->forfiles samp* $$-avg = wavg($$ row)
this will create a series of new files named "samplk1-avg", "samplk2-avg", "samplk3-avg", etc.
Use * as a wildcard for one or more letters. Use ? for a single letter. For example, if you have files called samplk1, samplk2 and samplkcombined, using samplk* will find samplk1 and samplk2, but also samplkcombined. In contrast using samplk? will only fine samplk1 and samplk2
If you are using UCINET 6.578 or later, you can combine forfiles with the Run command to execute a script for each file. For example, we could create a text file called doit.txt containing these commands:
h = holes($$)
c = centrality($$)
dsp corr(h c)
and then execute the script for all files that begin with "samplk":
->forfiles samplk* doit.txt $$
and it will execute doit.txt for samplk1, samplk2 and samplk3