想请教下各位大神老师,如何针对以下15个样本里的每一条记录,匹配出在上一年份、同省范围内(即prov一样)、生产同类别商品(即commodity_type一样)的所有城市(即提取城市代码),同时也提取出这些城市的消费金额?最终数据结构希望如图片所示(红字部分就是预期得到的内容),后附部分数据~谢谢各位大神啦~ [handshake]
|
* Example generated by -dataex-. To install: ssc install dataex
clear
input int year byte prov int city byte commodity_type long consumption
1995 14 1401 6 15820
1999 14 1401 6 144288
2000 14 1401 6 13681
2001 14 1401 6 127879
1999 15 1501 6 1283
1998 15 1505 6 2168
1997 15 1501 6 3188
2000 15 1501 9 3137
1994 14 1402 6 13654
2007 14 1402 8 3589
1998 14 1403 6 2245
1999 14 1402 9 2790
2000 14 1401 9 34117
2001 14 1401 9 13689
1994 14 1405 6 34588
end