Announcement

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

  • Dividing values of a variable by a specific value of of that variable

    Dear all,

    I am currently working with a country-year (several countries for the period 1991-2017) panel dataset which contains data for the variable p. The dataset looks as follows:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str3 iso3code int year float p
    "AFG" 1991  .26324314
    "AGO" 1991  .07728866
    "ALB" 1991  .16126928
    "ARE" 1991  .07935231
    "ARG" 1991  .10957538
    "AUS" 1991  .12007634
    "AUT" 1991  .15538613
    "BDI" 1991   .1682758
    "BGD" 1991   .0887369
    "BGR" 1991  .21465053
    "BOL" 1991  .08842834
    "BRA" 1991 .062516764
    "BTN" 1991  .07286633
    "BWA" 1991  .07766687
    "CAN" 1991  .18250223
    "CHE" 1991  .17977367
    "CHL" 1991  .17008154
    "CHN" 1991  .13463156
    "CMR" 1991  .05731851
    "COD" 1991  .07688629
    "COL" 1991   .0827645
    "CYP" 1991   .0847219
    "DEU" 1991  .14722322
    "DNK" 1991   .1661195
    "DZA" 1991   .2676517
    "ECU" 1991  .07355322
    "EGY" 1991  .16315214
    "ESP" 1991  .13816103
    "FIN" 1991  .15071706
    "FRA" 1991  .20819467
    "GBR" 1991   .2048492
    "GRC" 1991   .1799765
    "GTM" 1991  .06381295
    "HND" 1991  .06313922
    "HUN" 1991  .11392532
    "IND" 1991  .18820088
    "IRL" 1991  .09506503
    "IRN" 1991   .2333436
    "IRQ" 1991   .2749146
    "ISR" 1991  .08214688
    "ITA" 1991  .15988086
    "JOR" 1991  .10949718
    "JPN" 1991  .12740448
    "KEN" 1991  .09040132
    "KOR" 1991  .09588184
    "KWT" 1991  .07757444
    "LBN" 1991  .08384028
    "LBY" 1991  .12150127
    "LSO" 1991   .0899893
    "MAR" 1991   .3298471
    "MDG" 1991  .07864311
    "MEX" 1991   .1063788
    "MLI" 1991  .07417072
    "MLT" 1991  .11386012
    "MMR" 1991  .06519765
    "MNG" 1991  .12883416
    "MOZ" 1991  .07243199
    "MRT" 1991  .07706072
    "MWI" 1991  .07670119
    "NAM" 1991   .0788064
    "NCL" 1991  .06329099
    "NER" 1991    .093072
    "NGA" 1991  .09590288
    "NLD" 1991  .08545596
    "NOR" 1991  .14657421
    "NPL" 1991  .11307379
    "NZL" 1991  .07793946
    "OMN" 1991  .07882214
    "PAK" 1991   .2136493
    "PER" 1991   .0902002
    "POL" 1991  .10701688
    "PRK" 1991  .06605012
    "PRT" 1991  .12656064
    "PRY" 1991  .08081456
    "PSE" 1991          .
    "QAT" 1991   .0965965
    "ROU" 1991  .15691066
    "RWA" 1991  .08875785
    "SAU" 1991   .3373662
    "SOM" 1991  .07675452
    "SWE" 1991  .14027049
    "SWZ" 1991   .0770141
    "SYR" 1991  .23945548
    "TCD" 1991  .07753914
    "THA" 1991  .06408442
    "TUN" 1991   .3140195
    "TUR" 1991  .18619636
    "TWN" 1991  .06229275
    "TZA" 1991  .08104041
    "UGA" 1991  .07718216
    "URY" 1991  .08086365
    "USA" 1991  .09329012
    "VEN" 1991  .06689537
    "YEM" 1991  .10683016
    "ZAF" 1991  .13975191
    "ZMB" 1991  .09120012
    "ZWE" 1991   .1167359
    "AFG" 1992  .24156703
    "AGO" 1992  .06865555
    "ALB" 1992  .14868183
    "ARE" 1992  .07002092
    "ARG" 1992  .10474285
    "ARM" 1992  .11770034
    "AUS" 1992   .2012137
    "AUT" 1992  .14467098
    "AZE" 1992   .1654236
    "BDI" 1992  .14846717
    "BGD" 1992   .0888667
    "BGR" 1992  .20970023
    "BIH" 1992   .1588485
    "BLR" 1992  .07767703
    "BOL" 1992  .08009361
    "BRA" 1992  .06287865
    "BTN" 1992  .06487154
    "BWA" 1992  .06817044
    "CAN" 1992   .1454488
    "CHE" 1992   .1738271
    "CHL" 1992  .15844306
    "CHN" 1992   .1382531
    "CMR" 1992  .05908934
    "COD" 1992   .0681892
    "COL" 1992 .068500444
    "CYP" 1992  .07864647
    "DEU" 1992   .1561983
    "DNK" 1992   .1711161
    "DZA" 1992   .3448201
    "ECU" 1992  .06423723
    "EGY" 1992   .1562376
    "ESP" 1992  .12005354
    "EST" 1992  .14839287
    "FIN" 1992  .11015483
    "FRA" 1992  .20277137
    "GBR" 1992  .20375232
    "GEO" 1992  .11114666
    "GRC" 1992  .14920314
    "GTM" 1992  .05865807
    "HND" 1992  .05796011
    "HRV" 1992   .2229043
    "HUN" 1992  .10576737
    "IND" 1992  .17048697
    "IRL" 1992  .08708007
    "IRN" 1992  .21193446
    "IRQ" 1992  .19460054
    "ISR" 1992    .080836
    "ITA" 1992  .14190578
    "JOR" 1992  .09652802
    "JPN" 1992  .11426197
    "KAZ" 1992  .35702685
    "KEN" 1992  .06940021
    "KGZ" 1992   .1524303
    end
    I would like to do something simple, namely divide the value for p of each country by the value for p of a numeraire country for a specific year, in this case that is the U.S.A for the year 1991. Thus, each observation for the variable p must be divided by one specific observation, namely the value for p when iso3code= USA and year=1991.

    I cannot seem to find a code that does this for me. Any help on this is greatly appreciated.

    Best,

    Satya

  • #2
    Code:
    levelsof p if iso3code == "USA" & year == 1991, local(denominator)
    gen wanted = p / `denominator'

    Comment


    • #3
      Also, you can use egen

      Code:
      egen tag= total(p*(iso3code=="USA" & year==1991))
      gen wanted = p / tag

      Comment


      • #4
        Hi Andrew,

        Thank you for your quick reply. The code works nicely, thank you very much.

        Dear Wouter, when I run your code I get the following error message:

        Code:
        levelsof p if iso3code == "USA" & year == 1991, local(denominator)
        .00038048037095 .0004697096301243 .0007038792828098 .0008579761488363 .0009798991959542 .0015394628280774 .0017182430019602 .00211666733
        > 95783 .0022665564902127 .0025458771269768 .0027865841984749 .0028062791097909 .0028716719243675 .0029905596747994 .0034353379160166 .0
        > 039047510363162 .0040462627075613 .0042656501755118 .0047482550144196 .0048120710998774 .0048432582989335 .0049041877500713 .004977861
        > 8849814 .005068966653198 .0053378529846668 .005473721306771 .0055558034218848 .0056483601219952 .0059587187133729 .0060196509584785 .0
        > 061805183067918 .0067850556224585 .007019167765975 .0070378142409027 .0078131137415767 .0078581497073174 .0080751059576869 .0081981550
        > 902128 .0084753427654505 .0085794655606151 .0087825944647193 .008819006383419 .0092310355976224 .0100997714325786 .0105353314429522 .0
        > 106950588524342 .0109319947659969 .0110032716766 .0110845323652029 .0111898304894567 .0112182246521115 .0116062015295029 .011795192025
        > 6019 .0119498400017619 .0120646636933088 .0121012721210718 .012231120839715 .0125358058139682 .0129894809797406 .0136651489883661 .014
        > 0029666945338 .0142961395904422 .0144330086186528 .0155414612963796 .015974024310708 .0160693824291229 .016839437186718 .0170254353433
        > 847 .0174056552350521 .0176927503198385 .0178615152835846 .0183163415640593 .0187019538134336 .0189949721097946 .0202429220080376 .022
        > 6994510740042 .0238628797233105 .0240337364375591 .0253792367875576 .0275697875767946 .0282382946461439 .0282889660447836 .03204524144
        > 5303 .0337539874017239 .034239936619997 .0361092537641525 .0413518138229847 .0477488189935684 .0504243969917297 .0513256080448627 .052
        > 2535517811775 .0540465712547302 .0555361360311508 .0556063801050186 .0641877353191376 .0673421546816826 .070031926035881 .092946030199
        > 5277 .0932901203632355 .0934827923774719 .0942697525024414 .0985209196805954 .0990510284900665 .100793868303299 .1026020050048828 .114
        > 3061742186546 .1438032239675522 .1882069855928421 .2119858115911484 .2616786658763886 .2877330780029297 .3118483424186707 .31379541754
        > 7226 .5680322647094727 .5861462950706482
        
        . gen wanted = p /`denominator'
        invalid '.0004697096301243'
        It is not a problem, since I got another code from Andrew anyways. In any case thank you for your help as well.

        Best,

        Satya

        Comment


        • #5
          That is quite odd, your results of the levelsof command suggest that you have many observations for USA in year 1991, not just one. If this is the case, Andrew's code will still work because it will take the sum of all the observations, but the question is whether this is what you want or if there's something wrong with your data. I would try the following could at least to see where the multiple observations are coming from.
          Code:
          list if iso3code == "USA" & year == 1991

          Comment


          • #6
            #1 led me and more crucially others to suppose that you have just one value for each country and year.

            #4 implies otherwise!

            So, what Andrew's code will give you is the total of all values for the USA and 1991, and that is what you are dividing by.

            Is that really what you want?

            Comment


            • #7
              #5 == #6

              What's more, dividing by a specific value of a variable is not what is achieved by adding several values together.
              Last edited by Nick Cox; 21 Jan 2020, 10:36.

              Comment


              • #8
                Hi Wouter and Nick,

                You are both right. I have multiple values for each country and year. The variable p stands for price, and I have price data for several products. I'm sorry if that was unclear. I will post 2 new examples (one sorted on year, one sorted on p). Where I also include the itemcode identifier to make it clearer hopefully:

                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str3 iso3code int(itemcode year) float p
                "AFG"  534 1991   .01044707
                "AFG"   56 1991   .08989608
                "AFG" 1163 1991    .1505086
                "AFG"  526 1991   .01935146
                "AFG"  977 1991    .2729439
                "AFG" 1020 1991    .0239488
                "AFG"  944 1991    .2186808
                "AFG"  619 1991   .02437559
                "AFG"   44 1991    .0485511
                "AFG" 1137 1991   .04656297
                "AFG"  767 1991   .06336077
                "AFG"  234 1991  .017783467
                "AFG"  515 1991   .03770711
                "AFG" 1130 1991   .03439341
                "AFG"  558 1991   .04443339
                "AFG"  882 1991   .24785133
                "AFG"  328 1991   .04336498
                "AFG"  711 1991 .0029909965
                "AFG"  521 1991  .006354847
                "AFG"   15 1991   .26324314
                "AFG"  222 1991  .012116384
                "AFG"  116 1991   .06072822
                "AFG"  223 1991  .014095712
                "AFG" 1717 1991     .489979
                "AFG"  156 1991  .035204463
                "AFG"  157 1991  .006203289
                "AFG" 1058 1991   .15174474
                "AFG"  267 1991   .02335694
                "AFG"  867 1991   .23005177
                "AFG"  536 1991   .01505424
                "AFG"  568 1991  .008772944
                "AFG"  723 1991  .003796601
                "AFG" 1185 1991   .00376097
                "AFG"  403 1991     .075262
                "AFG" 1012 1991   .24662706
                "AFG"   79 1991  .018592516
                "AFG"  569 1991  .003810728
                "AFG"  512 1991  .009982804
                "AFG"  211 1991   .02123568
                "AFG" 1032 1991   .05872981
                "AFG"   27 1991   .12356815
                "AFG"  260 1991   .06285662
                "AFG"  463 1991   .07815912
                "AFG" 1017 1991   .06126965
                "AFG" 1094 1991   .12575386
                "AFG"  541 1991  .013046714
                "AFG" 1182 1991   .03596971
                "AFG" 1062 1991  .062736064
                "AFG"  982 1991   .06129406
                "AFG"  490 1991   .01929924
                "AFG"  289 1991   .01916585
                "AFG"  987 1991   .02560749
                "AFG"  329 1991  .004571578
                "AFG"  567 1991  .014827643
                "AFG"  560 1991   .14772598
                "AFG" 1127 1991   .04226551
                "AFG"  221 1991   .02683148
                "AFG"  333 1991  .005675049
                "AFG"  329 1992  .005205645
                "AFG"  987 1992   .02234963
                "AFG"  711 1992 .0021194755
                "AFG" 1017 1992    .0809384
                "AFG" 1020 1992   .02301245
                "AFG" 1130 1992   .03255898
                "AFG"  882 1992   .25696707
                "AFG"   79 1992  .015199434
                "AFG"   44 1992   .04327079
                "AFG"  515 1992  .032312483
                "AFG"  944 1992   .21188156
                "AFG"  221 1992  .026354507
                "AFG" 1062 1992   .05674021
                "AFG"  260 1992    .0556915
                "AFG" 1182 1992  .027743125
                "AFG"  512 1992   .00982201
                "AFG" 1137 1992   .04442188
                "AFG"  333 1992  .006189016
                "AFG"  267 1992    .0216116
                "AFG"  558 1992   .04183062
                "AFG"  534 1992    .0101033
                "AFG"   15 1992   .24156703
                "AFG"  977 1992    .3342215
                "AFG"  521 1992  .005483819
                "AFG"  463 1992   .07557896
                "AFG"  567 1992  .013501748
                "AFG"   27 1992   .11421239
                "AFG"  536 1992  .012083966
                "AFG"  222 1992  .012034614
                "AFG"  569 1992  .003883001
                "AFG"  568 1992  .008235155
                "AFG"  767 1992   .05880783
                "AFG"  619 1992  .025463836
                "AFG" 1127 1992   .04041017
                "AFG"  328 1992   .04734122
                "AFG" 1012 1992    .3093937
                "AFG" 1032 1992    .0784557
                "AFG"  723 1992   .00336355
                "AFG"   56 1992   .07070889
                "AFG"  116 1992   .04961219
                "AFG"  526 1992   .02570753
                "AFG" 1058 1992   .13769227
                end
                Code:
                * Example generated by -dataex-. To install: ssc install dataex
                clear
                input str3 iso3code int(itemcode year) float p
                "UZB" 1717 1998     -.18798397
                "UZB" 1717 1997      -.1579937
                "UZB" 1717 1996     -.12921299
                "SLE" 1717 1998     -.08819226
                "SLE" 1717 1993     -.08623613
                "SLE" 1717 1995     -.07215298
                "SLE" 1717 1994      -.0686602
                "SLE" 1717 1996    -.063925155
                "SLE" 1717 1997     -.06286517
                "STP" 1717 1998     -.05507535
                "STP" 1717 1997     -.04927799
                "LBY" 1717 1996      -.0490328
                "SOM" 1717 1997     -.04294503
                "GUY" 1717 1998     -.03906693
                "GUY" 1717 1996      -.0384905
                "LBY" 1717 1997    -.034294672
                "STP" 1717 1996     -.03415019
                "SOM" 1717 1996    -.032075725
                "STP"  882 1998     -.03146648
                "STP" 1717 1995    -.027496876
                "GUY" 1717 1995      -.0274018
                "LBY" 1717 1998     -.02690997
                "STP"  882 1997    -.026628233
                "UZB"  463 1993     -.02563298
                "URY"  156 2003     -.02385527
                "FJI" 1717 1993    -.022225127
                "URY"  156 2004    -.020058146
                "SOM" 1717 1998    -.018990004
                "URY"  156 2002    -.018041711
                "URY"  156 2005    -.016737388
                "GUY" 1717 1994    -.016376823
                "URY"  156 2006     -.01604525
                "STP"   56 1998     -.01540839
                "SOM"  882 1997    -.014490376
                "STP"  882 1996     -.01418343
                "STP"   56 1997    -.013867511
                "STP"  149 1998    -.013437666
                "ETH"  137 2016    -.012875044
                "SOM"  882 1998     -.01234192
                "STP"  149 1997     -.01204117
                "SOM"  882 1996    -.011159736
                "URY"  156 2007    -.010340468
                "STP"   56 1996     -.00969023
                "UZB"  463 1998    -.008747918
                "UZB" 1166 1993    -.008615316
                "STP"  149 1996    -.008471992
                "STP"   56 1995    -.007810087
                "UZB"  619 1993    -.007661118
                "MLI" 1182 1991    -.006923473
                "STP"  149 1995     -.00691411
                "MLI" 1182 1994    -.006029513
                "MLI" 1182 1992    -.005399955
                "MLI" 1182 1993    -.004916664
                "MRT" 1717 1995    -.004474806
                "VEN"  242 1992    -.004250118
                "MRT" 1717 1991    -.003740953
                "VEN"  242 1991   -.0037390215
                "URY"  156 2001    -.003571402
                "UZB"  463 1997    -.003563368
                "URY"  156 2008    -.002944721
                "VEN"  242 1993   -.0027390616
                "GUY" 1717 1993     -.00268359
                "MOZ"  156 2016    -.002504466
                "UZB" 1020 1998   -.0020571104
                "SOM"  982 1997     -.00204088
                "UZB"   56 1998   -.0017889383
                "SOM"  982 1998   -.0017500896
                "SOM"  982 1996    -.001638547
                "SOM" 1020 1997   -.0015651666
                "CMR"  234 2015   -.0014911118
                "UZB" 1166 1998   -.0014900132
                "SOM" 1020 1998   -.0013446034
                "SOM" 1020 1996   -.0012362134
                "CMR"  234 2016   -.0012005805
                "SAU"   44 2014   -.0011914793
                "URY"  156 2009   -.0011382402
                "MLI"  571 2016    -.001099096
                "CMR"  234 2014    -.000927597
                "TUN"  157 2013   -.0007475818
                "UZB"  619 1998   -.0006209615
                "SOM"   56 1997   -.0005991738
                "AZE"  417 1994  -.00057557964
                "UZB" 1020 1997   -.0005503857
                "LTU"  292 1992   -.0003309116
                "TUN"  157 2016 -.000020503147
                "URY"  101 2003   .00008546033
                "SAU"   44 2015   .00008781369
                "THA"  780 2015   .00009469924
                "URY"  101 2004   .00010209122
                "URY"  101 2002   .00011639371
                "URY"  101 2005    .0001166816
                "URY"  101 2006   .00011886474
                "RUS"  777 1998   .00014218863
                "URY"  101 2007   .00014405648
                "SOM"   56 1998   .00014641036
                "RUS"  777 1999   .00014777595
                "RUS"  777 2003   .00015523584
                "JPN"  777 2002   .00015765213
                "EGY"  329 2004   .00015810257
                "RUS"  777 2002   .00015830967
                end

                Having inserted this example, I realize where the confusion comes from. I was very sloppy and forgot to add the itemcode variable in the previous example, which basically is a group identifier. My sincere apologies for this. In essence, this data contains for each country and year, price data for several items. I would like to divide the price of each item of each country for a specific year, by the price of the "numeraire item". The price "numeraire" item here is then the price of a item sold in the U.S. in 1992. So I would like to divide the price of each item by the price of an item sold in USA in the year=1991.

                Hopefully, it is clearer now. My apologies for the confusion. Indeed Wouter, the code by Andrew is not what I want, I do not want to divide by the totals. Sorry Andrew for the unclear example.




                Best,

                Satya
                Last edited by satya otil; 21 Jan 2020, 11:09.

                Comment


                • #9
                  OK. The principle is I think similar:


                  Code:
                  egen reference = total(price * (year == 1991) * (country == "USA")), by(itemcode) 
                  
                  gen rel_price = price / reference 
                  Over many years and countries I would expect working with logarithm of price to work well.

                  Comment


                  • #10
                    Hi Nick,

                    Thank you for your quick reply. I run the code that you sent me:

                    Code:
                    egen reference = total(p * (year == 1991) * (iso3code == "USA")), by(itemcode) 
                    
                    gen rel_price = p / reference
                    It works, but for some items the value is zero, causing that the value for rel_price is missing:
                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input str3 iso3code int(itemcode year) float(p reference rel_price)
                    "AFG"  156 1991 4.0864797 5.346552 .7643205
                    "AFG"  944 1991 4.0864797 5.346552 .7643205
                    "AFG"  403 1991 4.0864797 5.346552 .7643205
                    "AFG"  987 1991 4.0864797 5.346552 .7643205
                    "AFG" 1094 1991 4.0864797 5.346552 .7643205
                    "AFG"  723 1991 4.0864797        0        .
                    "AFG" 1185 1991 4.0864797        0        .
                    "AFG"  882 1991 4.0864797 5.346552 .7643205
                    "AFG"  490 1991 4.0864797 5.346552 .7643205
                    "AFG"  221 1991 4.0864797 5.346552 .7643205
                    "AFG"  568 1991 4.0864797 5.346552 .7643205
                    "AFG"  541 1991 4.0864797        0        .
                    "AFG"  558 1991 4.0864797 5.346552 .7643205
                    "AFG"   15 1991 4.0864797 5.346552 .7643205
                    "AFG"  328 1991 4.0864797 5.346552 .7643205
                    "AFG"  560 1991 4.0864797 5.346552 .7643205
                    "AFG" 1062 1991 4.0864797 5.346552 .7643205
                    "AFG"  977 1991 4.0864797 5.346552 .7643205
                    "AFG"  223 1991 4.0864797 5.346552 .7643205
                    "AFG"  711 1991 4.0864797        0        .
                    "AFG"  234 1991 4.0864797 5.346552 .7643205
                    "AFG"  211 1991 4.0864797        0        .
                    "AFG"   44 1991 4.0864797 5.346552 .7643205
                    "AFG"  116 1991 4.0864797 5.346552 .7643205
                    "AFG" 1717 1991 4.0864797 5.346552 .7643205
                    "AFG"   56 1991 4.0864797 5.346552 .7643205
                    "AFG" 1012 1991 4.0864797 5.346552 .7643205
                    "AFG" 1020 1991 4.0864797 5.346552 .7643205
                    "AFG"  619 1991 4.0864797 5.346552 .7643205
                    "AFG"  515 1991 4.0864797 5.346552 .7643205
                    "AFG" 1130 1991 4.0864797        0        .
                    "AFG" 1182 1991 4.0864797 5.346552 .7643205
                    "AFG"  463 1991 4.0864797 5.346552 .7643205
                    "AFG" 1032 1991 4.0864797        0        .
                    "AFG"  536 1991 4.0864797 5.346552 .7643205
                    "AFG" 1137 1991 4.0864797        0        .
                    "AFG"  767 1991 4.0864797 5.346552 .7643205
                    "AFG"  157 1991 4.0864797 5.346552 .7643205
                    "AFG"  329 1991 4.0864797 5.346552 .7643205
                    "AFG"  260 1991 4.0864797 5.346552 .7643205
                    "AFG"  333 1991 4.0864797 5.346552 .7643205
                    "AFG" 1058 1991 4.0864797 5.346552 .7643205
                    "AFG" 1127 1991 4.0864797        0        .
                    "AFG"  521 1991 4.0864797 5.346552 .7643205
                    "AFG" 1017 1991 4.0864797 5.346552 .7643205
                    "AFG"  982 1991 4.0864797        0        .
                    "AFG"   79 1991 4.0864797 5.346552 .7643205
                    "AFG"   27 1991 4.0864797 5.346552 .7643205
                    "AFG"  222 1991 4.0864797 5.346552 .7643205
                    "AFG"  534 1991 4.0864797 5.346552 .7643205
                    "AFG"  567 1991 4.0864797 5.346552 .7643205
                    "AFG"  526 1991 4.0864797 5.346552 .7643205
                    "AFG"  512 1991 4.0864797 5.346552 .7643205
                    "AFG"  289 1991 4.0864797 5.346552 .7643205
                    "AFG"  267 1991 4.0864797 5.346552 .7643205
                    "AFG"  867 1991 4.0864797 5.346552 .7643205
                    "AFG" 1163 1991 4.0864797 5.346552 .7643205
                    "AFG"  569 1991 4.0864797 5.346552 .7643205
                    "AFG"  156 1992 4.0115604 5.346552 .7503079
                    "AFG" 1032 1992 4.0115604        0        .
                    "AFG"  333 1992 4.0115604 5.346552 .7503079
                    "AFG"  558 1992 4.0115604 5.346552 .7503079
                    "AFG" 1012 1992 4.0115604 5.346552 .7503079
                    "AFG" 1717 1992 4.0115604 5.346552 .7503079
                    "AFG"  711 1992 4.0115604        0        .
                    "AFG"  211 1992 4.0115604        0        .
                    "AFG"  534 1992 4.0115604 5.346552 .7503079
                    "AFG"  521 1992 4.0115604 5.346552 .7503079
                    "AFG"  512 1992 4.0115604 5.346552 .7503079
                    "AFG"   79 1992 4.0115604 5.346552 .7503079
                    "AFG"  222 1992 4.0115604 5.346552 .7503079
                    "AFG"  490 1992 4.0115604 5.346552 .7503079
                    "AFG"  260 1992 4.0115604 5.346552 .7503079
                    "AFG"  982 1992 4.0115604        0        .
                    "AFG"  767 1992 4.0115604 5.346552 .7503079
                    "AFG"  569 1992 4.0115604 5.346552 .7503079
                    "AFG"  116 1992 4.0115604 5.346552 .7503079
                    "AFG"  987 1992 4.0115604 5.346552 .7503079
                    "AFG"  567 1992 4.0115604 5.346552 .7503079
                    "AFG"  289 1992 4.0115604 5.346552 .7503079
                    "AFG"  403 1992 4.0115604 5.346552 .7503079
                    "AFG" 1163 1992 4.0115604 5.346552 .7503079
                    "AFG"  157 1992 4.0115604 5.346552 .7503079
                    "AFG"   27 1992 4.0115604 5.346552 .7503079
                    "AFG"  882 1992 4.0115604 5.346552 .7503079
                    "AFG"  568 1992 4.0115604 5.346552 .7503079
                    "AFG"  463 1992 4.0115604 5.346552 .7503079
                    "AFG"  977 1992 4.0115604 5.346552 .7503079
                    "AFG"  526 1992 4.0115604 5.346552 .7503079
                    "AFG" 1094 1992 4.0115604 5.346552 .7503079
                    "AFG"  867 1992 4.0115604 5.346552 .7503079
                    "AFG" 1137 1992 4.0115604        0        .
                    "AFG"  234 1992 4.0115604 5.346552 .7503079
                    "AFG"  619 1992 4.0115604 5.346552 .7503079
                    "AFG"  723 1992 4.0115604        0        .
                    "AFG"  329 1992 4.0115604 5.346552 .7503079
                    "AFG" 1062 1992 4.0115604 5.346552 .7503079
                    "AFG" 1182 1992 4.0115604 5.346552 .7503079
                    "AFG"  944 1992 4.0115604 5.346552 .7503079
                    "AFG"   15 1992 4.0115604 5.346552 .7503079
                    end
                    Would you know why this could be happening?

                    Best,

                    Satya

                    Comment


                    • #11
                      Yes. I do know. If there is no price for that item in the USA in 1991, then the total will be returned as 0 and the result will be missing because you are dividing by 0.

                      It's arguable that a zero for missing is spurious, because no price is known, but price / missing is missing, so the result would be the same. So for example check this


                      Code:
                      list if itemcode == 723 & iso3code == "USA" & year == 1991
                      and I guess there are no such observations.

                      Comment


                      • #12
                        I'm not sure whether the code in #9 is what Satya wants. I believe Satya's aim is to use a specific item in the USA in 1991 as the reference, rather than calculating relative prices with the US price in 1991 as a base for each item independently. The code would then rather be something like:
                        Code:
                        egen reference = total(p * (year == 1991) * (country == "USA") * (itemcode == 477))
                        gen rel_price = p / reference
                        (Itemcode 477 is made up here as Satya never mentioned which item is to be used as numeraire)

                        Comment


                        • #13
                          I can believe #12. Again, only Satya knows what is wanted.

                          In some internet circles, IANAL is standard for "I am not a lawyer".

                          IANAE needs to be introduced to Statalist. So, opposite of "I am Spartacus!" is "I am not an economist".

                          Comment


                          • #14
                            Hi Nick,

                            That would explain why I get the 0's indeed, thank you for that insight.

                            Dear Wouter, My aim is to calculate relative prices with the US price in 1991 as a base for each item independently. For example, if I have prices for apples,oranges, and berries for OECD countries for the period 2000-2010, I would like to divide all these prices with the price of the corresponding item sold in the U.S. in 1991. So divide the prices of apples in the different OECD countries for the different years with the price of apples in the U.S. in 1991, and divide the prices of oranges in the different OECD countries with the price of oranges in the U.S. in 1991, etc. So I do not want to use 1 specific item as the reference, and therefore think Nick's command is the right one for me. Sorry if I was unclear once again, hopefully it is clear now.

                            Best,

                            Satya

                            Comment

                            Working...
                            X