Hi all,

I must premise I am not expert in trade data. However I need to compute RCA and have little doubts on how to do it (also because it seems that my computations do not match with the ones in here for instance).
So first, my data comprise a product index at level 4, country index (notice that I have collapsed data so that a unique country-product couple appears) and trade flows (BACI/CEPI database):

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 hs4codeprod float hs4_id str3 exporter_iso_3digit double tradevalue
"0101" 1 "DZA" 10.108162879943848
"0101" 1 "AND" 120.53255593776703
"0101" 1 "ARG"  9629.224909305573
"0101" 1 "AUS"  86472.81986558437
"0101" 1 "AUT"  2132.536598801613
"0101" 1 "BHS"                100
"0101" 1 "BHR" 193.47499799728394
"0101" 1 "BGD" 20.354000091552734
"0101" 1 "BRB"  65.63900136947632
"0101" 1 "BEL"  36924.96172940731
"0101" 1 "BMU" 439.79998779296875
"0101" 1 "BOL"                  6
"0101" 1 "BIH" 14.426000356674194
"0101" 1 "BRA"   3185.37881398201
"0101" 1 "BGR"  2936.695587873459
"0101" 1 "BLR"  3290.506613612175
"0101" 1 "CMR" 18.554000854492188
"0101" 1 "CAN"  51635.36661911011
"0101" 1 "CHL"  7072.357475161552
"0101" 1 "CHN" 478.48726654052734
"0101" 1 "COL"  682.3816673755646
"0101" 1 "COD"   1.25600004196167
"0101" 1 "CRI" 285.25163316726685
"0101" 1 "HRV"  675.0100674629211
"0101" 1 "CUB" 150.91200494766235
"0101" 1 "CYP"  2.759000062942505
"0101" 1 "CZE"  611.9732294082642
"0101" 1 "DNK"  7549.552221417427
"0101" 1 "DOM"  47.41800117492676
"0101" 1 "ECU" 128.93145322799683
"0101" 1 "SLV"  34.58388030529022
"0101" 1 "ETH" 1.3109999895095825
"0101" 1 "EST"  81.73368859291077
"0101" 1 "FIN"  67.15455412864685
"0101" 1 "FRA" 103380.44628405571
"0101" 1 "DEU"  94944.91963219643
"0101" 1 "GRC"  40.57899987697601
"0101" 1 "GTM"   79.3317883014679
"0101" 1 "HND" 10.833800911903381
"0101" 1 "HKG"   1573.73548412323
"0101" 1 "HUN"  5300.647402644157
"0101" 1 "ISL"   7488.07611989975
"0101" 1 "IDN" 3.6710000038146973
"0101" 1 "IRN"  48.51900100708008
"0101" 1 "IRQ" 10.982000350952148
"0101" 1 "IRL" 355687.92628383636
"0101" 1 "ISR" 112.05600118637085
"0101" 1 "ITA"  6544.395604729652
"0101" 1 "JAM" 118.79399871826172
"0101" 1 "JPN"  4830.717058181763
"0101" 1 "KAZ"   8.38122296333313
"0101" 1 "JOR" 135.80199933052063
"0101" 1 "KEN" 13.632729887962341
"0101" 1 "KWT" 34.195000886917114
"0101" 1 "KGZ" 1546.4839825630188
"0101" 1 "LAO"  88.71299934387207
"0101" 1 "LBN"  23.25412082672119
"0101" 1 "LVA" 1074.1950693130493
"0101" 1 "LTU"  5950.128066778183
"0101" 1 "MAC" 1802.6154975891113
"0101" 1 "MDG"  6.294000148773193
"0101" 1 "MYS"  7336.998687505722
"0101" 1 "MLT" 2.1480000019073486
"0101" 1 "MUS" 62.599600076675415
"0101" 1 "MEX" 3035.7134602069855
"0101" 1 "N/A"  26.95199966430664
"0101" 1 "MAR" 135.54013633728027
"0101" 1 "OMN" 26.007999420166016
"0101" 1 "NLD"  98475.89318478107
"0101" 1 "ANT" 12.333000183105469
"0101" 1 "ABW"                 14
"0101" 1 "NZL"  66011.96702873707
"0101" 1 "NIC"  20.61124575138092
"0101" 1 "NER"  272.1799956560135
"0101" 1 "NOR" 1484.0610361099243
"0101" 1 "PAN" 139.26964402198792
"0101" 1 "PRY"  9.400000095367432
"0101" 1 "PER"  796.0619459152222
"0101" 1 "POL"  43520.12171816826
"0101" 1 "PRT"  817.3880338668823
"0101" 1 "TLS"  117.2300033569336
"0101" 1 "QAT"  336.9500012397766
"0101" 1 "ROU" 10837.174761652946
"0101" 1 "RUS" 1038.1541653871536
"0101" 1 "KNA"               7.25
"0101" 1 "SAU"  1366.751883506775
"0101" 1 "IND"  1312.660629272461
"0101" 1 "SGP"  539.7666878700256
"0101" 1 "SVK"  731.0369747877121
"0101" 1 "SVN"  280.2810171842575
"0101" 1 "ZAF"   3074.45375084877
"0101" 1 "ZWE" 118.55313777923584
"0101" 1 "ESP" 12153.734238862991
"0101" 1 "SWE"  8527.239937543869
"0101" 1 "CHE"  5531.058223366737
"0101" 1 "SYR"   37.1279993057251
"0101" 1 "THA" 215.53899943828583
"0101" 1 "TGO"  1.562000036239624
"0101" 1 "TTO" 18.759000301361084
"0101" 1 "ARE" 151855.88510131836
end

Now what I am actually doing is adopting two solutions (which however gave me two distinct results):

First, I compute the RCA manually according to its very definition:

Code:
egen ctry_exp = sum(tradevalue), by(ctry_id)
egen prod_exp = sum(tradevalue), by(hs4_id)
egen exp_tot = sum(tradevalue)

gen num_rca = tradevalue/ctry_exp
gen den_rca = prod_exp/exp_tot

gen rca_cp = num_rca/den_rca
Second way I compute it using a package provided by sac in STATA called RCA. The problem here is that also viewing the help, I don't understand what is meant by "exporting varieties" and hence I am not sure of the results.
The code is here:

Code:
rca tradevalue, j(exporter_iso_3digit) m(hs4codeprod)index(BRCA)
where BRCA calculates Balassa revealed comparative advantage index.

Any idea on that? Moreover, could you please provide me an official source where I can check that my RCAs are in line?

Thank you very much,

Federico