Hello,

I have two datasets which are related, in the first one i have "all types of capital net (so after taxes and so on)". In the second data set i have "consumption of fixed capital" in the first variable with is the same as depreciation. The last variable of each one is the value of capital and the depreciation of each "time" (year). the other variables are possible grouping variables.

The end goal is to create a new variable which is,

averagedelta = depreciation / net capital
I have to do this at an industry level, therefore, I need to group it by branca_attivitarev2 or by breakdownbyindustrynacerev2, and then calculate the depreciation rate per year.

Now My question is, how could I merge these two files? I was thinking That I should perhaps merge them by prodotti1? Since it's the most micro data I have?

And more importantly, how would I go about grouping the variables per year and industry (branca_attivitarev2 or breakdownbyindustrynacerev2) ?

Or is there an easier way to to this by clustering somehow?


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str35 aggregate str6 branca_attivitarev2 str10 prodotti1 str82 nonfinancialassets int time float value
"stock of non financial assets (net)" "_T" "N111"   "dwellings "                          2010   2542957
"stock of non financial assets (net)" "_T" "N111"   "dwellings "                          2011   2567567
"stock of non financial assets (net)" "_T" "N111"   "dwellings "                          2012   2586043
"stock of non financial assets (net)" "_T" "N111"   "dwellings "                          2013 2599558.5
"stock of non financial assets (net)" "_T" "N1132"  "ict equipment "                      2010 38846.438
"stock of non financial assets (net)" "_T" "N1132"  "ict equipment "                      2011  39527.07
"stock of non financial assets (net)" "_T" "N1132"  "ict equipment "                      2012  39062.74
"stock of non financial assets (net)" "_T" "N1132"  "ict equipment "                      2013 38337.742
"stock of non financial assets (net)" "_T" "N11321" "computer hardware "                  2010  18563.67
"stock of non financial assets (net)" "_T" "N11321" "computer hardware "                  2011  18090.36
"stock of non financial assets (net)" "_T" "N11321" "computer hardware "                  2012  17256.59
"stock of non financial assets (net)" "_T" "N11321" "computer hardware "                  2013 16429.092
"stock of non financial assets (net)" "_T" "N11322" "telecommunications equipment "       2010  20282.77
"stock of non financial assets (net)" "_T" "N11322" "telecommunications equipment "       2011  21436.71
"stock of non financial assets (net)" "_T" "N11322" "telecommunications equipment "       2012  21857.03
"stock of non financial assets (net)" "_T" "N11322" "telecommunications equipment "       2013 22000.596
"stock of non financial assets (net)" "_T" "N115"   "cultivated biological resources "    2010  6049.093
"stock of non financial assets (net)" "_T" "N115"   "cultivated biological resources "    2011  5944.182
"stock of non financial assets (net)" "_T" "N115"   "cultivated biological resources "    2012  6852.966
"stock of non financial assets (net)" "_T" "N115"   "cultivated biological resources "    2013  6606.761
"stock of non financial assets (net)" "_T" "N117"   "intellectual property products "     2010  161942.6
"stock of non financial assets (net)" "_T" "N117"   "intellectual property products "     2011 161998.86
"stock of non financial assets (net)" "_T" "N117"   "intellectual property products "     2012 162041.25
"stock of non financial assets (net)" "_T" "N117"   "intellectual property products "     2013  161663.3
"stock of non financial assets (net)" "A"  "N11"    "total fixed assets by type of asset" 2010 209133.03
"stock of non financial assets (net)" "A"  "N11"    "total fixed assets by type of asset" 2011  206363.4
"stock of non financial assets (net)" "A"  "N11"    "total fixed assets by type of asset" 2012  203592.3
"stock of non financial assets (net)" "A"  "N11"    "total fixed assets by type of asset" 2013 199244.53
"stock of non financial assets (net)" "A"  "N11K"   "total construction "                 2010  161473.4
"stock of non financial assets (net)" "A"  "N11K"   "total construction "                 2011  158884.4
"stock of non financial assets (net)" "A"  "N11K"   "total construction "                 2012  156149.3
"stock of non financial assets (net)" "A"  "N111"   "dwellings "                          2010         0
"stock of non financial assets (net)" "A"  "N111"   "dwellings "                          2011         0
"stock of non financial assets (net)" "A"  "N111"   "dwellings "                          2012         0
"stock of non financial assets (net)" "A"  "N112"   "other buildings and structures "     2010  161473.4
"stock of non financial assets (net)" "A"  "N112"   "other buildings and structures "     2011  158884.4
"stock of non financial assets (net)" "A"  "N112"   "other buildings and structures "     2012  156149.3
"stock of non financial assets (net)" "A"  "N1132"  "ict equipment "                      2010  183.6101
"stock of non financial assets (net)" "A"  "N1132"  "ict equipment "                      2011   193.278
"stock of non financial assets (net)" "A"  "N1132"  "ict equipment "                      2012 184.64014
"stock of non financial assets (net)" "A"  "N11322" "telecommunications equipment "       2010  30.47981
"stock of non financial assets (net)" "A"  "N11322" "telecommunications equipment "       2011 32.768135
"stock of non financial assets (net)" "A"  "N11322" "telecommunications equipment "       2012  33.71726
"stock of non financial assets (net)" "A"  "N115"   "cultivated biological resources "    2010  5502.228
"stock of non financial assets (net)" "A"  "N115"   "cultivated biological resources "    2011  5418.072
"stock of non financial assets (net)" "A"  "N115"   "cultivated biological resources "    2012  6358.372
"stock of non financial assets (net)" "A"  "N117"   "intellectual property products "     2010 148.70393
"stock of non financial assets (net)" "A"  "N117"   "intellectual property products "     2011 130.17282
"stock of non financial assets (net)" "A"  "N117"   "intellectual property products "     2012 119.11266
"stock of non financial assets (net)" "A"  "N1173"  "computer software and databases "    2010 110.96416
end

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str28 aggregate str6 branca_attivitarev2 str10 prodotti1 str82 nonfinancialassets int time float value
"consumption of fixed capital" "_T"  "N11"    "total fixed assets by type of asset"                2010 281510.72
"consumption of fixed capital" "_T"  "N11"    "total fixed assets by type of asset"                2011 284309.22
"consumption of fixed capital" "_T"  "N11"    "total fixed assets by type of asset"                2012 285494.94
"consumption of fixed capital" "_T"  "N11"    "total fixed assets by type of asset"                2013 286035.75
"consumption of fixed capital" "_T"  "N111"   "dwellings "                                         2010  57883.57
"consumption of fixed capital" "_T"  "N111"   "dwellings "                                         2011  58706.21
"consumption of fixed capital" "_T"  "N111"   "dwellings "                                         2012  59443.36
"consumption of fixed capital" "_T"  "N111"   "dwellings "                                         2013  60102.32
"consumption of fixed capital" "_T"  "N112"   "other buildings and structures "                    2010  72204.91
"consumption of fixed capital" "_T"  "N112"   "other buildings and structures "                    2011 72955.305
"consumption of fixed capital" "_T"  "N112"   "other buildings and structures "                    2012   73605.2
"consumption of fixed capital" "_T"  "N112"   "other buildings and structures "                    2013 74112.766
"consumption of fixed capital" "_T"  "N1131"  "transport equipment "                               2010   23392.3
"consumption of fixed capital" "_T"  "N1131"  "transport equipment "                               2011 23056.676
"consumption of fixed capital" "_T"  "N1131"  "transport equipment "                               2012  22459.35
"consumption of fixed capital" "_T"  "N1131"  "transport equipment "                               2013  22033.56
"consumption of fixed capital" "_T"  "N1132"  "ict equipment "                                     2010 11045.525
"consumption of fixed capital" "_T"  "N1132"  "ict equipment "                                     2011 11323.753
"consumption of fixed capital" "_T"  "N1132"  "ict equipment "                                     2012 11330.208
"consumption of fixed capital" "_T"  "N1132"  "ict equipment "                                     2013 11224.133
"consumption of fixed capital" "_T"  "N11321" "computer hardware "                                 2010  5656.364
"consumption of fixed capital" "_T"  "N11321" "computer hardware "                                 2011  5688.564
"consumption of fixed capital" "_T"  "N11321" "computer hardware "                                 2012  5578.888
"consumption of fixed capital" "_T"  "N11321" "computer hardware "                                 2013  5413.109
"consumption of fixed capital" "_T"  "N117"   "intellectual property products "                    2010  40870.35
"consumption of fixed capital" "_T"  "N117"   "intellectual property products "                    2011  41018.25
"consumption of fixed capital" "_T"  "N117"   "intellectual property products "                    2012  40968.91
"consumption of fixed capital" "_T"  "N117"   "intellectual property products "                    2013  40779.91
"consumption of fixed capital" "A"   "N111"   "dwellings "                                         2010         0
"consumption of fixed capital" "A"   "N111"   "dwellings "                                         2011         0
"consumption of fixed capital" "A"   "N111"   "dwellings "                                         2012         0
"consumption of fixed capital" "A"   "N11M"   "machinery and equipment and weapons systems "       2010  5842.494
"consumption of fixed capital" "A"   "N11M"   "machinery and equipment and weapons systems "       2011  5890.845
"consumption of fixed capital" "A"   "N11M"   "machinery and equipment and weapons systems "       2012  5877.965
"consumption of fixed capital" "A"   "N11O"   "other machinery and equipment and weapons systems " 2010  5271.135
"consumption of fixed capital" "A"   "N11O"   "other machinery and equipment and weapons systems " 2011  5326.548
"consumption of fixed capital" "A"   "N11O"   "other machinery and equipment and weapons systems " 2012  5317.553
"consumption of fixed capital" "A"   "N115"   "cultivated biological resources "                   2010  368.1727
"consumption of fixed capital" "A"   "N115"   "cultivated biological resources "                   2011  365.2976
"consumption of fixed capital" "A"   "N115"   "cultivated biological resources "                   2012  361.5069
"consumption of fixed capital" "BTF" "N11K"   "total construction "                                2010  22772.81
"consumption of fixed capital" "BTF" "N11K"   "total construction "                                2011  22911.03
"consumption of fixed capital" "BTF" "N11K"   "total construction "                                2012  23023.32
"consumption of fixed capital" "BTF" "N112"   "other buildings and structures "                    2010  22772.81
"consumption of fixed capital" "BTF" "N112"   "other buildings and structures "                    2011  22911.03
"consumption of fixed capital" "BTF" "N112"   "other buildings and structures "                    2012  23023.32
"consumption of fixed capital" "BTF" "N11321" "computer hardware "                                 2010 1148.4613
"consumption of fixed capital" "BTF" "N11321" "computer hardware "                                 2011  1135.418
"consumption of fixed capital" "BTF" "N11321" "computer hardware "                                 2012 1099.6528
"consumption of fixed capital" "BTF" "N11322" "telecommunications equipment "                      2010  572.4916
end