Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Arrays - unidentified number of elements


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Arrays - unidentified number of elements
Date   Sun, 9 Feb 2003 17:08:25 -0000

Karina Fortuny
> 
> folder.
> I can define an array:
> 
> local array "file1 file2 file3 .... fileN"
> and loop through the elements.
> 
> But I do not want to type all the names (if there are
> 50 or so; it's possible to make typos, and it's
> difficult to audit).
> 
> Is it possible to define the array without listing the
> elements if the number of elements is known? Is it
> possible if the number is not known?
> 
> I'm currently using STATA 7, but might be upgrading to
> STATA 8.

Here there is 

1. a general question about what I will call lists -- 
the term "arrays" doesn't have a fixed meaning in Stata, 
so far as I know; perhaps there is some sense carried 
over here from use of Some Alternative Software which 
I don't know or use 

2. a particular question about handling 
lists of files in a folder. 

1. There are lots of tricks to handling lists, 
even in Stata 7. In Stata 8, there are even more.
In either case, too many to list in an email.  

2. Let me focus instead on files in a folder. 

What OS are you using? I guess Windows. 

Here is one idiosyncratic way to do this. I have
a little program, which we may call "oscmd". 

program def oscmd 
        version 7
        tempfile file 
        ! `0' > `file' 
        type `"`file'"' 
end     

How does this work? At what Windows XP calls 
the command prompt I can go 

dir /b *.dta 

to get a bare list of *.dta files in the 
current directory. But don't fire that up: stay 
in Stata. Install -oscmd- and type in Stata 

oscmd dir /b *.dta

and a list of filenames will appear 
in your results window. Now copy and paste
to the do file editor. 
 
> "The soul unfolds itself like a lotus of countess petals." 
> - Kahlil Gibran

Shouldn't it be "countless"? 

Nick 
n.j.cox@durham.ac.uk 
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index