Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Wages calculation over different groups

    Dear all,

    I have a simple question, I want to calculate the wage premium between different groups of observations. However, the way the data is shaped does not allow me to do that. Any hint?

    My idea is create a variable that has wages for tech_intensity==3 on the top and wages for tech_intensity==1 in the bottom (fraction). Thank you very much!

    Code:
     * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int year float(tech_intensity lwages r_output_worker real_output labor_intensity Real_Val) double(FemaleEmployees GrossFixed ValueAdded OutputINDSTAT4 Wages Employment Establishments) float region
    1963 1 17.237011  29719.19 2697258240 .00016222493 1046816064                  .  40382280.00465117  330532181.2161458  851659318.3222506   158918786.453125  90562.61503416857                  .  3.787879
    1964 1 17.152292 30002.137 2677261312 .00017505143 1049830720                  .  48281163.43317972 332096448.37270343  846906939.0734177 155104993.40206185  87058.19495412844                  .  3.863636
    1965 1 17.113222 31198.873 2558225152 .00016884458 1015406592                  .  50638823.26808511  327637872.6313253   825453989.979021 154773960.47355768  81253.44612068965                  .  3.828571
    1966 1  17.00735 31721.736 2539627264 .00016593043 1012345088                  . 53891014.681102365 337195275.84210527  845907467.3370289  155293405.8400901  81565.78131634819                  .  3.863014
    1967 1 17.148325  32448.94 2596242176 .00015762808 1015501184                  .  53331842.49808429 339177395.35294116  867144879.6365546  159132208.6091476  75360.08582089552                  . 3.8607595
    1968 1 16.983665 31485.875 2519751424  .0001601339  970201088                  . 118656603.58715597  332132183.8801431  862594923.1539855  157723974.3548387  72425.55775577558                  . 3.8651686
    1969 1 17.153461 32947.457 2787787264  .0001519683 1070869312                  .  69737231.35034014  381140247.9661654  992219942.4761904 183152186.14095238          75596.125                  .  3.840909
    1970 1  17.10529  33050.79 2762053120 .00013868292 1022882048                  .  71558194.13253012 377443452.75043327 1019197530.9963369 187211540.95081967          73841.688                  .   3.84375
    1971 1  17.09905 34406.473 3586350080 .00016043913 1062296256                  .  73680967.99410029 404823397.93162394 1366698214.5076923 194621771.87197232  72967.04081632652                  .  3.824742
    1972 1 17.217674  37186.56 3970439168 .00014611144 1187558528                  .  83023641.09734513  472549350.5768567 1579903919.1113043 224376846.33274338  74549.66456692913                  .  3.770833
    1973 1 17.360172  40502.96 4327792128 .00014214602 1286076288  61322.57142857143 100254489.22157435  579055861.8321799 1948588463.0400696 260505292.83508772       77047.715625                  .  3.867347
    1974 1  17.16357  39804.76 3850725888  .0001421022 1137346816  59344.28571428572 113733065.40462428  608290993.8165585 2059496412.7318256 266271694.59415585  75064.45413533834                  .  3.855769
    1975 1 17.210127  39966.16 3691250944 .00014256428 1103303168 59313.857142857145 115616957.86627907  644512872.7983739  2156305700.995208 288231793.36422765  72854.56413994169                  .  3.851852
    1976 1 17.327444  42082.11 3823742976  .0001340003 1165756672  63499.42857142857 119866684.20505618  712665917.0359477 2337581391.1961412          314324355  73786.60957910014                  .  3.824074
    1977 1 17.500357  43927.66 4121115392  .0001275586 1239180672  67058.57142857143 140973008.97191012  803918503.1940298 2673573574.0971336  373264957.9540412  82460.00287769784                  .  3.861111
    1978 1 17.545843  45931.25 4543623680 .00012265211 1378098048  71419.57142857143 161769743.95251396  963864690.0925926 3177885952.1824102 430910195.66614175  82217.50357653791                  .  3.861111
    1979 1 17.548418  45759.68 4556200960  .0001374479 1372248320  72489.28571428571 169653992.60305342 1080302482.8010035 3586869292.0752864  483525654.7199367  85086.08815028901                  . 3.9134614
    1980 1  17.48008  45604.85 4177253376 .00013547546 1315298304  72512.14285714286 176802452.45742092 1181247445.5638125  3751521544.744914    493240790.40553  85203.79799426933                  . 3.8440366
    1981 1 17.390171  41399.23 3686271232  .0001593492 1160476416  34091.90476190476 159708099.87556562 1137653680.1671925 3613774464.8662615 478522457.82218844  84744.69440459111 1646.2910447761194  3.857143
    1982 1 17.456337  41456.13 3.7126e+09 .00015062153 1179642880  36973.06122448979 156144938.70465118 1179839530.5697865  3713219040.992236   482950712.599686   89911.9067669173 1872.4822429906542  3.887931
    1983 1 17.373537  41601.66 3761008896 .00015983984 1243865344 28719.195488721805 142705306.74831462 1259413724.2753873 3808021660.5861516  488260654.0904762  86013.82789317507 1543.8676748582232   3.86087
    1984 1  17.41499  40167.85 3731448576  .0001553477 1285984128   30880.5035971223 152203369.68360278 1333243955.0756013 3868579168.8515625 485785523.17912775  86322.15820029027 1599.9135135135134 3.9285715
    1985 1 17.397758  41965.89 3860619264  .0001743391 1306458752  33415.86559139785 167331697.29069766 1347612170.1597223 3982228824.2852616   505559094.523511  87065.96480938417 1714.6442141623488  3.957983
    1986 1  17.48454  51511.37 4606076416 .00015883234 1562871552 30016.102040816328 201491923.40931374 1565476318.7138102  4613753209.563945  595161989.9487578  84466.40401146132 1514.3248638838475      4.04
    1987 1 17.655518   56956.7 5203587584 .00015389817 1769542656 28438.803571428572  224233419.4480198 1819237318.4444444 5349721836.2817335  698911364.1873016  86367.58714285714 1736.8973451327433  4.112903
    1988 1 17.777891  60168.77 5646147072 .00018798887 1944387200 27342.532934131737 253099755.85819072 2079360091.2969284    6038083855.4448        777738058.7  89452.20289855072 1508.5582191780823 4.1157026
    1989 1 17.732876  61729.28 5285994496   .000155833 1877133696 27121.598930481283   296421210.708134 2106926087.4269104  5933087843.287218  770531491.2445141  92606.06578947368 1687.8848167539268  4.048387
    1990 1 17.512238  62101.14 4625940992  .0001997255 1856347776 23141.227467811157 290607007.53091687  2158777815.203852   5379583851.37408   735192833.136294  96150.98881118881 1658.6426282051282 4.0916033
    1991 1 17.366022  63376.25 4471430144 .00016764284 1726944256 17504.883116883117  260859458.6031042 2012465750.9728434  5210707023.595474  711246982.0474074  80042.67255434782 1569.1888217522658 4.0592594
    1992 1  17.46292  69684.86 4527080960   .001274962 1920747520 35752.845814977976 258845275.49665925 2250956136.7808895   5305361606.12117    777830679.47793  82504.23829201102  1805.275494672755  3.984733
    1993 1 17.242548   66411.3 4312485888 .00018197387 1802865792 38782.225694444445  238216513.7133758 2143757648.6539052  5127905223.686587  735921838.1240982  81881.93717277487 1476.0280112044818  4.044776
    1994 1  17.21505  68023.99 4390784512   .000459974 1821159424  41206.66336633663 228983649.39350912 2193586470.5752606  5288700023.970013  681695968.1767181  81724.24641460234 1395.9016620498614 4.0444446
    1995 1 17.286957 74941.945 4739880960  .0002926396 1935728640 49911.517699115044 260705300.10714287 2414982798.9661765  5913396795.228205  729621699.4163265  80852.13425345044 1887.6498599439776  4.021164
    1996 1 17.418821  72580.73 4936918528  .0002776332 1974324096  27568.61176470588 239388730.61770624 2520882704.7941604  6303622128.783572  768664990.8812155  80320.30279898219 2256.3099579242635 4.0500894
    1997 1 17.503483  71977.13 4710868480 .00028083142 1954246016  18919.98148148148  286154421.9589322     2493617978.925  6011068213.350806  743705495.2871429  81491.22506738544 2378.4051593323215  4.051948
    1998 1 17.395948  75717.52 4602076672    .00044092 1812701440 25667.515570934254 292006260.39880955     2255604918.275  5726517940.486018  678990124.8877006  80542.37958115184           2457.325  4.144144
    1999 1 17.370247 70350.164 4850882560  .0004803279 1944646528  23658.89024390244 342377526.11946905 2440045261.0789475  6086644929.824611  752460871.1107872  79548.58108108108 2835.8853503184714 4.1767955
    2000 1 17.205532  64995.64 4474771968 .00027113367 1761236352  26302.40157480315 315927287.01304346     2337894490.375  5939887123.931601  689241905.1023513  78703.65699208443 2698.1750380517506  4.184162
    2001 1 17.155552   63371.2 4088220928 .00028061832 1588400384   27060.4280155642  290875760.2894737  2131500932.923521  5486052006.490067  646742100.6528354  78338.82398956975 2664.8963963963965 4.2075133
    2002 1 17.258614   67966.2 4424695808  .0002735327 1694079744 30522.345679012346 360320660.12093025  2221220834.191111  5801513741.942544  672237424.1923642         84041.8375 3607.4506578947367 4.1781077
    2003 1 17.405739  77100.14 4866770432 .00023845454 1804744832 26501.322097378277  561082836.6513158  2492803802.931402  6722226825.440559  776302712.0206186  84491.94269340974 3035.9364820846904  4.179439
    2004 1 17.465818  80388.38 5188041216  .0002543553 1831753856 25785.962546816478  380473663.6892779 2686724912.1379824  7609559632.465084  863561554.2205663  95160.17423133236  3207.207920792079 4.1767955
    2005 1 17.510994  74845.48 5151882240 .00027309396 1790913280 27486.716475095785  468725516.0413223 2818897414.1597013  8109062641.687411  872078520.0423601   94930.2987012987 3317.9200626959246  4.184397
    2006 1  17.51897  74216.92 4988681216  .0002825906 1710856960  33436.19512195122  406342027.7119675 2818636871.8807855  8218852285.312417  905629998.6072993  99434.18539325842 3890.5335365853657 4.2083335
    2007 1 17.633587  75093.79 5256410112  .0002091311 1904170752 29817.486166007904 1042742927.4802784   3287709439.76393  9075630116.783857 1003088666.1729324  97942.44695898161 3361.5233333333335 4.1985817
    2008 1 17.661009  72478.08 5163257856 .00015880592 1413979648 28444.477777777778  1215291736.622807 2680787721.7097244  9789107152.983957 1085647909.4576523  95020.53682719546          3183.7056  4.183099
    2009 1 17.659977  83643.94 5427088896  .0001720023 1425969920      28403.1015625 1250688096.6361606  2465620876.959828   9383888419.38688   981601116.830703  92094.50277777777 3114.8188854489163 4.1985817
    2010 1 17.619686  86793.33 5542642176 .00016444635 1381052288 27799.791519434628  1370489704.892057 2551263918.2150683 10239107641.010164 1007187756.3515732  91346.93368700265 3169.2306569343064   4.22695
    2011 1 17.512472 75111.125 5525745664  .0001621555 1433028224  24467.28838951311  644814946.9044586 2881103102.4071527 11109511339.639593  886356895.4433285  63836.78731836195  3343.471615720524 4.2083335
    2012 1 17.686546 75662.125 5810798592   .000182114 1327805824  32491.41987179487  736095625.9562738  2684269969.998679 11747013394.213116  983822622127.7079  62686.88205128205  2862.392156862745       4.2
    2013 1 17.595308  81365.07 6142454272  .0000814739 1300819328  64334.66451612903 22993413907.600784 2645975028.6240106 12494264076.166666 1082126720.3980978  88883.26726342711 2988.1867647058825 4.1944447
    2014 1 17.563587  79905.07 6140194816 .00016443197 1268160896  57894.07575757576  574771962.5132576 2603745574.2734375 12606843243.851622 1065857105.1884058  85650.57829839704  2982.029197080292 4.1944447
    2015 1 17.515036  75015.22 6489161216  .0001402097 1330255872  57545.99392097264  448541897.0907372  2533361390.141522 12358066839.169426  977637832.1036835   86661.0630407911  3027.341991341991 4.1710525
    2016 1 17.665222 72735.516 7045041664 .00012858528 1470394752  62482.54113924051 528467360.11264825 2725744177.7280335 13059745956.545088 1028230376.3615819  91906.13914174252  3499.980769230769  4.253623
    2017 1 17.636332  74686.14 6873432064 .00012832657 1506456192 25412.144927536232 353485205.27678573 2915495020.3234043  13302382190.48895  912674374.4563954  92419.69841269842  3148.751987281399  4.253623
    2018 1  17.77817  69343.72 6486589952 .00013591796 1551321472 31334.430555555555  458974049.0516796  3132893831.915052 13099669160.693182  965220365.3122172 101650.96280400573 3376.3194706994327  4.280303
    2019 1 17.963007  75114.78 4919878144  .0001494524 1573840896               9680                  . 3145189739.1761656  9831966743.065292 1083937163.0698528  76385.71130434783  91.29166666666667 4.3157897
    1963 2  17.07814  56329.13 2435309824 .00012872554 1026579200                  .  67846018.17482518 324142378.61623615   768949071.923913 161438292.16666666              68464                  .  3.787879
    1964 2  17.01369  57651.37 2463811584 .00013241493 1061337536                  .  86276778.97841726 335736434.57835823  779385748.2418772 160482827.38007382  65640.60983606557                  .  3.863636
    1965 2 16.975307  62066.68 2448957696 .00012786956 1061636288                  .   89734269.2516129 342554657.31958765  790197040.4750831 163170069.34707904 62986.659442724456                  .  3.828571
    1966 2 16.861418  67341.67 2448316160  .0001208918 1067981440                  .  94942649.85454546 355726814.28664494  815493282.8449367  164931833.2483871 63102.914893617024                  .  3.863014
    1967 2 17.053318  71099.54 2504972544  .0001190852 1063008320                  . 100115877.46857142  355044781.1402985  836660845.2716419 167020000.83880597  58614.12365591398                  . 3.8607595
    1968 2 16.911821  72341.86 2489053696 .00011540084 1030801856                  . 103888063.17117117 352877855.48337597  852086049.6243523 168085668.48711342  57392.80805687204                  . 3.8651686
    1969 2 17.115509  71834.24 2834930176  .0001099912 1165679488                  . 131542481.69417475 414884750.87399465 1008998909.4592391 198304816.85558584  60425.07692307692                  .  3.840909
    1970 2 17.137428 71868.016 2905468928  .0001158856 1140882304                  . 134081665.14410481  420985553.3828715 1072117950.1481482 208754974.94708994  59527.76551724138                  .   3.84375
    1971 2  17.12379 75446.375 3313822208 .00011388795 1153497472                  .  143187924.1106383  439578662.9259259 1262842474.3144963  214714255.4154229 58686.842342342345                  .  3.824742
    1972 2  17.20249  83529.23 3661242112 .00010820996 1282523776                  . 164855433.62231758  510337584.4678218 1456869311.8681593 246969589.60152283  59731.37330316742                  .  3.770833
    1973 2 17.361671  94288.81 4138538240 .00010337665 1476165120            13263.6 180481503.48962656  664643338.1064357 1863376877.2039802  296233828.4185464  62043.61469933185                  .  3.867347
    1974 2 17.226221 131249.55 4143443712   .000101366 1373771904            13768.8  205964616.5942623  734738964.5264368 2216051711.9202733  309107864.0482759 60225.211087420044                  .  3.855769
    1975 2  17.27348 126912.28 3817155584 .00010400706 1231234944            15502.4 217966873.46443516  719246414.1770115 2229855030.6363635  327198821.6781609  57644.52057613169                  .  3.851852
    1976 2 17.395384    133097 4058790656 .00010354267 1310353408            18125.8  220794362.2195122  801062717.0817757  2481273934.949541  354800078.9976744 58733.825726141076                  .  3.824074
    1977 2 17.597399  134984.7 4465617408 .00009262293 1416959232            21790.8 246610497.05952382   919252295.035545  2897069186.047836 431148499.12189615  70060.61190965092                  .  3.861111
    1978 2 17.619822 133333.16 4905308160 .00008926595 1601017856            24677.4  274532673.9563492 1119778500.5673077  3430854227.763341 502040124.73318386  70174.77393075357                  .  3.861111
    1979 2 17.673136 151245.75 5340108288 .00009559908 1733332224            26652.8 303566454.01459855 1364565804.3004808 4203999985.0211267  575542888.1768707  72469.15145228215                  . 3.9134614
    1980 2  17.59796    163409 5104810496 .00009841398 1594082816            25738.2  292335433.3986486   1431619188.18894  4584545155.075556  591911978.3311547  71553.26422764227                  . 3.8440366
    1981 2 17.519363 148516.25 4511377920 .00011025833 1377847296 16089.379310344828 286270028.87138265 1350749670.9277651  4422653890.965293  565213919.2580645  70183.67206477733 1177.3819628647216  3.857143
    1982 2 17.556273 139797.11 4289994496  .0001127004 1284460544  16417.34328358209  282282443.4736842         1284674571  4290709317.993348  548451602.1088889  72550.08492569003 1343.2989417989418  3.887931
    1983 2 17.543436  143264.1 4281454336 .00011163772 1319680640 12680.108695652174 233817983.83601287 1336176695.3194103 4334972634.1632185  549145434.8276644  72101.93803418803 1165.8118279569892   3.86087
    1984 2  17.59548 138949.52 4243024128  .0001110955 1371524608 12481.309278350516 227661448.27906978 1421928140.5270936 4398955118.2561245  550604511.9287305   72634.4790794979 1209.8115183246073 3.9285715
    1985 2 17.589628 131186.55 4355681792  .0001157751 1400769152 14272.229007633588 261881109.41137123 1444893332.4292803  4492885879.620768  556709980.8587444  75209.03797468354 1264.6625615763546  3.957983
    1986 2 17.617466 108087.19 4738900480 .00013334511 1656706176  13418.42718446602   313789709.486014 1659467371.0665083  4746798883.415755   650803862.013245  71390.23991935483   1082.34335839599      4.04
    1987 2 17.843088 117559.31 5344445952 .00010475876 1883810304  12816.57142857143  325357213.0809859 1936714032.1615202  5494536006.519824   762254839.459276  73722.82995951417 1294.2456575682381  4.112903
    1988 2 17.973387 123604.17 6029030912  .0001060016 2173146880 12190.603305785124  354764945.6631944  2323999443.343826  6447546098.514942  868648057.3482352  76879.04771784232 1120.2385542168674 4.1157026
    1989 2 17.904278 125717.92 5641575424 .00011031728 2051953408 12251.764705882353  405469504.7147436 2303146540.3403263  6332197982.899787  852051211.8666667  76349.16155419222  1195.357142857143  4.048387
    1990 2  17.61436 142593.13 5321974272 .00012361453 2051387136           9769.725 399202988.48024315  2385592349.514739  6189012490.953684  847760437.8777293  81770.10303030303 1174.8190045248869 4.0916033
    1991 2 17.477777 139799.22 5003938816 .00011718353 1754882944  6718.248407643312  393283370.4102564  2045023661.952381   5831256894.21255  819504463.4692144  69528.31075697212 1138.2287581699347 4.0592594
    1992 2 17.589148 145417.22 5213829120 .00011093407 1981804672 23045.235294117647  395652772.9482201  2322510083.318182  6110173667.020534  918443642.8761061  73917.27663934426 1383.2847682119204  3.984733
    1993 2   17.3315 139075.06 4933388288 .00018127277 1920993920   20037.0351758794       364268223.25  2284221861.508969  5866209628.705882  871921938.2462527  81976.38943248532 1232.1006289308177  4.044776
    1994 2 17.290869 145783.89 5122853376 .00012310318 1937105792  22254.20792079208  354599464.0716418  2333243892.384106  6170476638.576108  811863923.5280665  83200.15354330708 1189.0373443983403 4.0444446
    1995 2  17.37933 150854.38 5555086848 .00013030191 2164136960 29337.586666666666  401909703.6696697  2699941463.066225  6930433722.003868  904633140.2169422  82548.79423076923 1622.0787234042552 4.0211267
    1996 2 17.487463 155584.31 5686517248  .0001254781 2118277632 10342.871951219513  375421487.7522936  2704687437.403084  7260734814.746534   924644562.125523            84231.8  1973.938689217759      4.05
    1997 2 17.674809  167730.5 5968913408 .00012330733 2308643072  7747.266272189349  458079945.9496855  2945828742.489311  7616333536.139584  982669306.2582057  85833.99360341151 2154.0418604651163 4.0518517
    1998 2  17.60721  146567.1 5660942336 .00015960496 2242277632  8710.886363636364  442762277.6818182   2790141061.63964  7044099423.558091  917772100.9958506  81458.04771784232  2201.228832951945 4.1438847
    1999 2 17.617985  168145.4 6193657856  .0001176943 2442840320  8755.445161290323  515887152.7414966 3065153872.8681054   7771492520.72627 1024404956.1896162  80903.11373390559 2528.2679900744415 4.1764708
    2000 2 17.489899 177616.84 6232467968 .00024256257 2306070272 10003.374193548387  495053888.3458904  3061116009.485849  8273081545.655172  960344371.2392242  81476.89361702128 2487.7607655502393 4.1838236
    2001 2 17.453442  160168.6 5697809408  .0001484791 2108212096  9045.625766871166  588735569.9369085  2829044934.448747  7645985349.539583   915029252.974026  78849.85416666667 2567.9297423887588  4.207143
    2002 2  17.56038 176762.64 6167660544 .00010771272 2215770368 11065.079470198676   529039866.003663 2905244362.9531617  8086831034.002183   963190875.516055   83000.2472406181  2941.974358974359  4.177778
    2003 2  17.73593  200979.2 6998030336 .00010745026 2472462592  8892.449101796406  521230763.2929293  3415089026.509709   9666029425.43584    1115200540.8125  80660.82045454545 2787.4631043256995 4.1791043
    2004 2 17.808125 291118.16 8064074752  .0003746808 2720522240   9013.70303030303  588628767.0816326 3990326161.6023254 11827981913.639738 1252490434.1105883  94810.54800936767 2913.8025974025973 4.1764708
    2005 2  17.91565  408174.2 9001906176 .00021992595 2862136832  9798.836477987421  656928404.3081967  4505003198.934117 14169000045.869179 1341842459.1702638  97002.91724137931  3187.256790123457  4.184397
    end
    Last edited by Hugo Rocha; 07 Apr 2022, 13:38.

  • #2
    Code:
    reshape wide lwages-region, i(year) j(tech_intensity)
    gen wanted = lwages3 / lwages1
    reshape long

    Comment


    • #3
      There are no instances of tech_intensity = 3 in your data, only 1 and 2 are instantiated.

      Assuming you meant a tech_intensity = 2 to tech_intensity 1 ratio, you have many observations in each of those categories. Do you want to average all of the years together and then take the ratio? Or do you want a separate ratio for each year? If the latter:
      Code:
      by year (tech_intensity), sort: assert tech_intensity == _n
      by year (tech_intensity): gen wanted_ratio = Wages[2]/Wages[1]
      Added: Crossed with #2, showing a different approach. If the real data set is large, the approach given here should be noticeably faster.
      Last edited by Clyde Schechter; 07 Apr 2022, 14:00.

      Comment


      • #4
        Thank you very much! The problem with dataex is that sometimes I do have a lot of variables constructed!

        Comment


        • #5
          Originally posted by Clyde Schechter View Post
          There are no instances of tech_intensity = 3 in your data, only 1 and 2 are instantiated.

          Assuming you meant a tech_intensity = 2 to tech_intensity 1 ratio, you have many observations in each of those categories. Do you want to average all of the years together and then take the ratio? Or do you want a separate ratio for each year? If the latter:
          Code:
          by year (tech_intensity), sort: assert tech_intensity == _n
          by year (tech_intensity): gen wanted_ratio = Wages[2]/Wages[1]
          Added: Crossed with #2, showing a different approach. If the real data set is large, the approach given here should be noticeably faster.
          A separate ratio for all years, I want to show the trend over time...

          Comment


          • #6
            Originally posted by Clyde Schechter View Post
            There are no instances of tech_intensity = 3 in your data, only 1 and 2 are instantiated.

            Assuming you meant a tech_intensity = 2 to tech_intensity 1 ratio, you have many observations in each of those categories. Do you want to average all of the years together and then take the ratio? Or do you want a separate ratio for each year? If the latter:
            Code:
            by year (tech_intensity), sort: assert tech_intensity == _n
            by year (tech_intensity): gen wanted_ratio = Wages[2]/Wages[1]
            Added: Crossed with #2, showing a different approach. If the real data set is large, the approach given here should be noticeably faster.
            I am sorry for one more question. What if I want to find correlations among observations?

            Comment


            • #7
              What if I want to find correlations among observations?
              You cannot correlate observations, only variables. To obtain correlations among different variables, use the -corr- command. See -help corr- for the simple instructions.

              Comment


              • #8
                Originally posted by Clyde Schechter View Post
                You cannot correlate observations, only variables. To obtain correlations among different variables, use the -corr- command. See -help corr- for the simple instructions.
                Correct, I am sure I didn't phrase the question correctly. My apologies. But, let's suppose, wages among different groups (tech_intensity) given this set up.

                Code:
                 * Example generated by -dataex-. To install: ssc install dataex
                clear
                input int year float(tech_intensity r_output_worker r_valworker Real_Val) double(Employment Wages)
                1963 1  29719.19 12588.478 1046816064  90562.61503416857   158918786.453125
                1963 2  56329.13 17030.705 1026579200              68464 161438292.16666666
                1963 3  23221.89 10041.694 1494496384 105618.79514824798  261178293.3425926
                1964 1 30002.137   12459.3 1049830720  87058.19495412844 155104993.40206185
                1964 2  57651.37 17643.648 1061337536  65640.60983606557 160482827.38007382
                1964 3 23628.066 10221.178 1506106880  101068.0735694823 253244685.39143732
                1965 1 31198.873 13215.375 1015406592  81253.44612068965 154773960.47355768
                1965 2  62066.68 19332.383 1061636288 62986.659442724456 163170069.34707904
                1965 3  24190.75 10570.057 1511148672  97212.14503816795  259845676.9688385
                1966 1 31721.736 13221.175 1012345088  81565.78131634819  155293405.8400901
                1966 2  67341.67  21649.27 1067981440 63102.914893617024  164931833.2483871
                1966 3  25552.31 10935.286 1578612352 100837.06297229219  273550041.4021448
                1967 1  32448.94 13714.375 1015501184  75360.08582089552  159132208.6091476
                1967 2  71099.54 24133.514 1063008320  58614.12365591398 167020000.83880597
                1967 3  26398.29 11340.295 1582756352  94157.75501113586  286044556.9650873
                1968 1 31485.875  13555.17  970201088  72425.55775577558  157723974.3548387
                1968 2  72341.86  23815.87 1030801856  57392.80805687204 168085668.48711342
                1968 3 26551.186  11249.52 1588783232  92361.25440313111 286248029.10683763
                1969 1 32947.457 13975.778 1070869312          75596.125 183152186.14095238
                1969 2  71834.24 24941.164 1165679488  60425.07692307692 198304816.85558584
                1969 3  27430.25 11849.647 1777045760           98127.89  337293239.4681818
                1970 1  33050.79  14176.34 1022882048          73841.688 187211540.95081967
                1970 2 71868.016  25472.44 1140882304  59527.76551724138 208754974.94708994
                1970 3  27790.35 11897.185 1691548800  95944.31679389313 350778234.84257203
                1971 1 34406.473 14564.286 1062296256  72967.04081632652 194621771.87197232
                1971 2 75446.375   24961.9 1153497472 58686.842342342345  214714255.4154229
                1971 3  29158.51 12413.466 1723317120  94622.96074766356 356200729.56458336
                1972 1  37186.56 16063.647 1187558528  74549.66456692913 224376846.33274338
                1972 2  83529.23 26537.273 1282523776  59731.37330316742 246969589.60152283
                1972 3  31882.14 13648.307 1949628288  97840.74199623353  415413827.3220339
                1973 1  40502.96 17524.363 1286076288       77047.715625 260505292.83508772
                1973 2  94288.81  29170.38 1476165120  62043.61469933185  296233828.4185464
                1973 3 34092.902 14610.023 2129761920  101564.8029739777 492533455.18333334
                1974 1  39804.76 16774.785 1137346816  75064.45413533834 266271694.59415585
                1974 2 131249.55  30937.12 1373771904 60225.211087420044  309107864.0482759
                1974 3  35121.64 14386.313 1887286272  97576.78938053097 506987313.12237096
                1975 1  39966.16 17008.682 1103303168  72854.56413994169 288231793.36422765
                1975 2 126912.28 30669.996 1231234944  57644.52057613169  327198821.6781609
                1975 3 36171.176 14703.896 1794900992   93292.7718696398  541361446.2179732
                1976 1  42082.11 18229.486 1165756672  73786.60957910014          314324355
                1976 2    133097 33460.008 1310353408 58733.825726141076  354800078.9976744
                1976 3  36790.72  15383.37 1954691200  96106.71183533447  588338661.8706564
                1977 1  43927.66 19255.662 1239180672  82460.00287769784  373264957.9540412
                1977 2  134984.7 33938.082 1416959232  70060.61190965092 431148499.12189615
                1977 3  38636.22 16354.545 2135449216 116783.89743589744  718628887.7757009
                1978 1  45931.25  19996.61 1378098048  82217.50357653791 430910195.66614175
                1978 2 133333.16 34905.598 1601017856  70174.77393075357 502040124.73318386
                1978 3  41312.18 17520.848 2388021248 118261.53050847458  843584338.1428572
                1979 1  45759.68  19654.17 1372248320  85086.08815028901  483525654.7199367
                1979 2 151245.75 36138.797 1733332224  72469.15145228215  575542888.1768707
                1979 3   41006.5 16952.975 2437338624 121668.79553264605  964414878.7838346
                1980 1  45604.85  19718.94 1315298304  85203.79799426933    493240790.40553
                1980 2    163409 35031.813 1594082816  71553.26422764227  591911978.3311547
                1980 3  41612.14 16667.867 2289652992 122116.54173764907 1018817109.8206521
                1981 1  41399.23  17590.41 1160476416  84744.69440459111 478522457.82218844
                1981 2 148516.25 30822.283 1377847296  70183.67206477733  565213919.2580645
                1981 3 38549.582   15128.2 2119058944 123467.70154373928 1003344294.1672727
                1982 1  41456.13 18366.547 1179642880   89911.9067669173   482950712.599686
                1982 2 139797.11   29291.6 1284460544  72550.08492569003  548451602.1088889
                1982 3 36772.645 14815.597 2103190272 128437.55116696589 1003852902.5947467
                1983 1  41601.66 18663.656 1243865344  86013.82789317507  488260654.0904762
                1983 2  143264.1 29651.396 1319680640  72101.93803418803  549145434.8276644
                1983 3  37091.59 14919.132 2245012224 130424.65467625899 1030607775.5229008
                1984 1  40167.85 18272.594 1285984128  86322.15820029027 485785523.17912775
                1984 2 138949.52  32717.91 1371524608   72634.4790794979  550604511.9287305
                1984 3 35704.504 14716.255 2404402688 130844.10178571429 1043495082.7792453
                1985 1  41965.89 18549.549 1306458752  87065.96480938417   505559094.523511
                1985 2 131186.55 32393.596 1400769152  75209.03797468354  556709980.8587444
                1985 3  37594.14 15232.716 2508724992 133079.05225225227 1094337046.2652671
                1986 1  51511.37  21932.85 1562871552  84466.40401146132  595161989.9487578
                1986 2 108087.19 32045.826 1656706176  71390.23991935483   650803862.013245
                1986 3  43661.08 18002.227 3023645952 131132.45149911818  1313186892.493282
                1987 1   56956.7  25018.98 1769542656  86367.58714285714  698911364.1873016
                1987 2 117559.31 34284.887 1883810304  73722.82995951417   762254839.459276
                1987 3  49604.77 20048.574 3482278144 134495.41666666666 1543538645.8461537
                1988 1  60168.77  26321.27 1944387200  89452.20289855072        777738058.7
                1988 2 123604.17 38172.336 2173146880  76879.04771784232  868648057.3482352
                1988 3  54156.52  22180.38 3956854528 139081.95315315315 1727791095.7678208
                1989 1  61729.28  27315.95 1877133696  92606.06578947368  770531491.2445141
                1989 2 125717.92  37704.36 2051953408  76349.16155419222  852051211.8666667
                1989 3  54378.79  22044.04 3760031488 137637.41563055062  1696438893.197318
                1990 1  62101.14  28494.67 1856347776  96150.98881118881   735192833.136294
                1990 2 142593.13  41355.98 2051387136  81770.10303030303  847760437.8777293
                1990 3  56631.61   23866.2 3649995776 138549.48844884487  1593334279.782765
                1991 1  63376.25   29249.6 1726944256  80042.67255434782  711246982.0474074
                1991 2 139799.22  41799.66 1754882944  69528.31075697212  819504463.4692144
                1991 3  60726.01   25589.1 3074638592           101093.5  1459278397.529118
                1992 1  69684.86  32203.88 1920747520  82504.23829201102    777830679.47793
                1992 2 145417.22  46123.75 1981804672  73917.27663934426  918443642.8761061
                1992 3  64829.23 27611.373 3266807040 102225.00154559505 1555762867.8013246
                1993 1   66411.3 28802.557 1802865792  81881.93717277487  735921838.1240982
                1993 2 139075.06  43417.68 1920993920  81976.38943248532  871921938.2462527
                1993 3  65220.93  25919.08 2982284288  100467.4066091954 1421180143.9349844
                1994 1  68023.99  31195.26 1821159424  81724.24641460234  681695968.1767181
                1994 2 145783.89  44114.35 1937105792  83200.15354330708  811863923.5280665
                1994 3  70119.91  27453.16 3008383744  97260.17202797203 1355465263.4829123
                1995 1 74941.945  27923.11 1935728640  80852.13425345044  729621699.4163265
                1995 2 150854.38  46816.65 2164136960  82548.79423076923  904633140.2169422
                1995 3  81533.44 29432.066 3068890112  86892.78101265823  1372549380.304762
                1996 1  72580.73  27549.58 1974324096  80320.30279898219  768664990.8812155
                end

                Comment


                • #9
                  I notice that this data example does contain observations with tech_intensity == 3. Given that, as you may have already figured out, the code in #2, assuming you want the ratio of wages in tech intensity 3 to those in tech intensity 1, should be changed to:
                  Code:
                  by year (tech_intensity), sort: assert tech_intensity == _n
                  by year (tech_intensity): gen wanted_ratio = Wages[3]/Wages[1]
                  Do not remove the -assert- command from this code. It is there to verify that all years have data for all three technology levels: the code shown will give incorrect results if that is not the case. So if you use this code and it breaks at the -assert- command, post back and I can show you (more complicated) code that will work on more irregular data.

                  If you want the correlations over time among the wage levels in the three groups, you have to convert those wage levels to three separate variables. That is one of the handful of situations where you need a wide layout in Stata. Here's how I would do that:
                  Code:
                  preserve
                  keep year tech_intensity Wages
                  reshape wide Wages, i(year) j(tech_intensity)
                  corr Wages*
                  restore

                  Comment


                  • #10
                    Originally posted by Clyde Schechter View Post
                    I notice that this data example does contain observations with tech_intensity == 3. Given that, as you may have already figured out, the code in #2, assuming you want the ratio of wages in tech intensity 3 to those in tech intensity 1, should be changed to:
                    Code:
                    by year (tech_intensity), sort: assert tech_intensity == _n
                    by year (tech_intensity): gen wanted_ratio = Wages[3]/Wages[1]
                    Do not remove the -assert- command from this code. It is there to verify that all years have data for all three technology levels: the code shown will give incorrect results if that is not the case. So if you use this code and it breaks at the -assert- command, post back and I can show you (more complicated) code that will work on more irregular data.

                    If you want the correlations over time among the wage levels in the three groups, you have to convert those wage levels to three separate variables. That is one of the handful of situations where you need a wide layout in Stata. Here's how I would do that:
                    Code:
                    preserve
                    keep year tech_intensity Wages
                    reshape wide Wages, i(year) j(tech_intensity)
                    corr Wages*
                    restore
                    Thank you very much! Yes, I realized it was Wages[3]

                    Comment


                    • #11
                      Originally posted by Clyde Schechter View Post
                      I notice that this data example does contain observations with tech_intensity == 3. Given that, as you may have already figured out, the code in #2, assuming you want the ratio of wages in tech intensity 3 to those in tech intensity 1, should be changed to:
                      Code:
                      by year (tech_intensity), sort: assert tech_intensity == _n
                      by year (tech_intensity): gen wanted_ratio = Wages[3]/Wages[1]
                      Do not remove the -assert- command from this code. It is there to verify that all years have data for all three technology levels: the code shown will give incorrect results if that is not the case. So if you use this code and it breaks at the -assert- command, post back and I can show you (more complicated) code that will work on more irregular data.

                      If you want the correlations over time among the wage levels in the three groups, you have to convert those wage levels to three separate variables. That is one of the handful of situations where you need a wide layout in Stata. Here's how I would do that:
                      Code:
                      preserve
                      keep year tech_intensity Wages
                      reshape wide Wages, i(year) j(tech_intensity)
                      corr Wages*
                      restore
                      I am sorry to "bug" you with the same type of question. If I want to calculate the wage gap by technological intensities by regions (which are coded). Should I do the the following?

                      Code:
                       by year region (tech_intensity), sort: assert tech_intensity == _n
                      Code:
                       by year region(tech_intensity): gen wanted_ratio = Wages[3]/Wages[1]
                      Last edited by Hugo Rocha; 13 Apr 2022, 15:30.

                      Comment


                      • #12
                        Yes, precisely so.

                        Comment


                        • #13
                          Thank you!

                          Comment

                          Working...
                          X