Hi everyone,
I have a series of household consumption datasets, each for every year, and I want to process each file a bit before merging them with other files.
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.
The relevant do file goes as follows:
To emphasize issue 1#, the following code didn't work (I got r(111): "f477fam_1997 not found") but using the explicit file path "${data}raw\households\f477fam_1997.dta" does work.
(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!
I have a series of household consumption datasets, each for every year, and I want to process each file a bit before merging them with other files.
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.
The relevant do file goes as follows:
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 //global "data" variable defined in the master do file 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!
Comment