I have two issues (examples follow bellow):
1. "use" command: it works when I explicitly state the file name, but not when I try to include a local variable in the path.
2. looping through a list of strings: this might be due to issue 1#, but I can't manage to define a list of strings - or an "an array of strings" in other programing languages - and loop through them.
Code:
clear
set more off
local hshall f477fam_1997 f478fam_1998 f479fam_1999 f461fam_2000 f462fam_2001 f463fam_2002 f464fam_2003 f466fam_2004 f467fam_2005 n468fam_2006 f469fam_2007 f474fam_2008 f472fam_2009
foreach filename of local hshall {
display `filename'
use "${data}raw\households\`filename'.dta", clear
if yearsur<2003 { //change variable names for 97'-02' data
rename v1 rectype
rename v2 hhnum
rename v15 weight
rename v13 typeloc
}
keep yearsur rectype hhnum weight typeloc
save "${data}\inter\hsh\hsh`yearsur'.dta", clear
}
(I tried putting hshall values in qoutes but it didn't work as well..)
This issue has agonized me for long time, although it honestly seems so trivial. I tried substantive googling but to no avail.
Thanks a lot!
0 Response to Looping through a list of strings; combining variables within strings
Post a Comment