Hi all,
I have a series of .dta files named "city_data_year2000.dta","city_data_year2001.dta", ...,"city_data_year2009.dta" . I would like to rename all the variables except one called tech as t_var where t is represented by the year of the .dta, i.e. last numbers in the names of the .dta and then merge city_data_yeart with city_data_year2000t+5, so for instance city_data_year2000 with city_data_year2005, city_data_year2001 with city_data_year2006 until city_data_year2004 with city_data_year2009.
I tried to write some code however I am stuck. Namely:
This code raises an error, namely: parentheses unbalanced.
Furthermore, without a local `time' I am unable to perform the merge.
How can I do that?
Thank you
I have a series of .dta files named "city_data_year2000.dta","city_data_year2001.dta", ...,"city_data_year2009.dta" . I would like to rename all the variables except one called tech as t_var where t is represented by the year of the .dta, i.e. last numbers in the names of the .dta and then merge city_data_yeart with city_data_year2000t+5, so for instance city_data_year2000 with city_data_year2005, city_data_year2001 with city_data_year2006 until city_data_year2004 with city_data_year2009.
I tried to write some code however I am stuck. Namely:
Code:
local myfilelist : dir "." files "city_data_year*.dta" foreach filename of local myfilelist { use "`filename'", clear local time substr("`filename'",-8,4) ds tech, not rename (`r(varlist)') ("`time'"_=) }
Furthermore, without a local `time' I am unable to perform the merge.
How can I do that?
Thank you
Comment