Statalist The Stata Listserver

[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: basic string operations

From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: basic string operations
Date   Mon, 17 Apr 2006 07:39:12 -0400

Code like this is meaningless:

> for file in `filename'{
> inflie "'$dict`$file.dct' ", using(" $data'$var' ")
Global $var is undefined, and putting single quotes around it doesn't help that. The for command is undocumented and deprecated.

Presuming you mean 'infile', you should first redefine filenames with forward slashes only so that Stata does not misinterpret the backslash operator:

global base "c:/program files/stuff/"
cd $base
forvalues i=1/200 {
infile "$base/dict/file`i'.dct", using("$base/data/file`i'"),clear
save file`i',replace
use file1,clear
forvalues i=2/200 {
append using file`i'
save allfiles,replace

You could use tempfiles, or you could include a step to remove the intermediate files within the second forvalues loop. If the filenames are not file1-file200, you could either use a local defining them and a foreach loop or you could capture the infile and append commands.

Kit Baum, Boston College Economics

* For searches and help try:

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