Hi All,

I'm struggling with the code for loops using wide data. I include a sample of the data and the code that I am using:

Code:
foreach x in a_* b_* {
gen `x'_pre_2001=((`x'2000+`x'1994)/2)
}
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int id double(a_1994 b_1994 a_2000 b_2000)
233 183.00000023841858 13624.999996344382 193.46520376205444  7277.969290733337
242                312 14339.000007144055  131.8211009502411  13230.46660065651
 38 1962.9999998807907 117587.00003860035 2439.2950912714005 115416.60470998287
145                349  34621.99999722597  284.3227996826172  33201.23075580597
195  220.9999998807907   6683.99999875563 317.89149165153503  8392.186589241028
146                163  6970.999999785423 161.47169876098633 4060.2099952697754
 98 190.00000131130219 11287.000004457967 280.94690465927124 18906.568377494812
273  308.9999997615814 12296.999990051876  54.13420104980469 2485.5112524032593
244 171.00000047683716 20275.000001510765  326.7100052833557 15995.360086917877
287                  8                256 379.46830129623413  21016.19201517105
end
As far as I can understand, the issue is that while running this code, the variable name that includes the year is not being recognized. Any suggestions on improving the code are much appreciated!