Hi! I am having a small issue with merging data from different Excel files in one Stata dataset. As far as I know this is only possible by loading and saving the data first in .dta format and then merge the .dta files via the -merge- command. I wanted to do the loading and saving with a loop but probably due to syntax issues, the code does not work as I want. I basically have Excel files called "1992.xlsx", "1993.xlsx" and so forth in this directory. I came up with this code:
This gives me an error message (invalid '1992'), so I thought it might be a problem that the local contains numbers instead of strings. I tried to solve that by writing:
but this again leads to the same problem. I am quite sure it is a syntax problem, but I cannot get my head around it. I would very much appreciate your help!
Thanks,
Michael
Code:
local filelist 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 foreach x of local filelist { clear import excel using "H:\Small scale industries\Data collection\Non-OECD\Value added\stata-readable colombia\Stata\`x'.xlsx", firstrow save "`x'.dta" }
Code:
local filelist `" "1992" "1993" "1994" "1995" "1996" "1997" "1998" "1999" "2000" "2001" "2002" "2003" "2004" "2005" "2006" "2007" "2008" "2009" "2010" "2011" "2012" "2013" "2014" "2015" "' foreach x of local filelist { clear import excel using "H:\Small scale industries\Data collection\Non-OECD\Value added\stata-readable colombia\Stata\"`x'".xlsx", firstrow save ""`x'".dta" }
Thanks,
Michael
Comment