Announcement

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

  • Replacing names

    I have this data file with countries that I will be merging with another data set so i wanted to change the country names in this one to match the other dataset's country names. So i generated a new variable to replace with the names I want to use. However, when I try to replace "Cote d'Ivoire" with "Cote d`Ivoire" (the difference is the apostrophe after the letter 'd'), it replaces all the countries with "Cote d`Ivoire". Below is the command I'm using:

    *Original dataset:


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str30 country_name int year double vb_50 long country double(_1_vb_6 _1_vb_8 _1_vb_11 _1_vb_13 _1_vb_1 _1_vb_5 _1_vb_22)
    "Cabo Verde"       1996 8.100000381 33         14.49810475         145226598.4         14.85290246         65538468.24 17.746521734404332 22.952545841758276         .699582407
    "Cabo Verde"       1997 8.100000381 33         1.094045086         128575542.6          .306654089         57572176.94 18.184139775191273  17.30287319737636         .695863673
    "Cabo Verde"       1998 8.300000191 33         11.57262059         137669065.2         15.06345364         63572664.48 13.360351840700996  39.97533550709496         .706620847
    "Cabo Verde"       1999 8.600000381 33         2.239022063         138489501.7        -4.379713272         59811440.36  9.394658722154247  7.632984137628171         .367855417
    "Cabo Verde"       2000 8.800000191 33         8.055817969         117266784.8         6.567738234         49948220.82 15.248624100622177  32.52807383699208         .414263908
    "Cabo Verde"       2001 8.699999809 33        -8.856556886         107898394.7        -19.64077311          40520080.7 5.2059216664565895 -4.524784081993612         .396626069
    "Cabo Verde"       2002 9.300000191 33         6.036638903         118317491.4         11.79889016         46847433.93  16.31022512523911  13.70859607067914         .447182205
    "Cabo Verde"       2003 8.899999619 33         1.188913809         150794909.1        -3.372038511         57015564.52 20.843538239618788 34.086872182622834         .615835443
    "Cabo Verde"       2004 9.199999809 33         7.270061224         168393112.8         -.205915318         59232128.78  8.029802568434178  11.60219091493736         .513253874
    "Cabo Verde"       2005 9.899999619 33         11.17254761         186727275.1          6.17089414         62726158.59   4.00697020355103 6.9958494458420954         .496661145
    "Cabo Verde"       2006        10.5 33         7.840790176         211521643.2        -2.347851873         64341989.31 15.854454789589447 30.764357576091307         .425894536
    "Cabo Verde"       2007 11.10000038 33         9.413792378         245960471.4   6.054993300411342   809614060.4962678 10.544041731036412        18.80788509         .489084652
    "Cabo Verde"       2008 11.60000038 33         18.19694565         322174717.9   7.237034698238296 -1507703211.4497066 15.653899861302893        20.86814587         .478993182
    "Cabo Verde"       2009 11.69999981 33        -4.643974255           319971396   4.379460393690879  1745582631.5982926 14.449508080312658        21.29698738         .544044637
    "Cabo Verde"       2010 11.30000019 33        -3.517614961         293550634.9 -1.2017883919582066  -2432264134.654168  8.264807178817046        20.20387547         .488298295
    "Cabo Verde"       2011 11.39999962 33          1.75091391         323561725.2   3.421015179586554 -1515097427.2588558 14.677482185583193        20.12624005         .504031768
    "Cabo Verde"       2012 10.89999962 33         -2.34196535         291500696.8   6.451047809540561  318521523.79647446  8.871645751701202          18.991361         .631569353
    "Cabo Verde"       2013 11.10000038 33          2.42321159         317040479.2  14.928573459548169   10921950201.70412  12.80691103981803        19.54789335         .616474913
    "Cabo Verde"       2014 11.19999981 33         6.610797838         339436391.5  -5.459970491037179  3429445715.2985163  10.90751516257486        20.76467226          .63743089
    "Cabo Verde"       2015 11.19999981 33         -.860675223         274420927.6 -2.8673137537278572  -9374722260.604391  5.247757905254751        19.96677378          .97317191
    "Cabo Verde"       2016 11.39999962 33         3.277428584         272630121.1   7.768249328945593    638758218.893115 19.543730267685497        19.42832188 -.6768793574430525
    "Congo, Dem. Rep." 1996         4.5 45         5.876742114          1867294093        -2.800001987           510113422        8.915511908        32.63564925        37.42208798
    "Congo, Dem. Rep." 1997 4.599999905 45        -19.83930946          1294303633        -21.79999902           380677539        6.333844344        21.53507077        33.03761611
    "Congo, Dem. Rep." 1998 4.699999809 45          -2.0367379          1270818056        -14.40000346         369392744.1        6.068504492        20.87741355         32.4023271
    "Congo, Dem. Rep." 1999           4 45         5.916667156         881686236.4         16.60000673         236250690.9         5.04613136        18.83213357        28.80415077
    "Congo, Dem. Rep." 2000         4.5 45         10.61193358          4276811594        -10.90000072          1891304348        10.01938467        22.65686142        7.636860145
    "Congo, Dem. Rep." 2001 5.599999905 45        -8.068686601          2232666667        -14.13703382          1473333333        20.32972112        30.80734662        18.51487867
    "Congo, Dem. Rep." 2002 6.099999905 45         5.077167171          2846941009          4.30976431          1851809654        21.81591795        33.53942526        18.84967793
    "Congo, Dem. Rep." 2003 5.699999809 45         2.422786548          2579197597        -4.465246396          1635432294        18.88368943        29.78097385        29.72276229
    "Congo, Dem. Rep." 2004 5.800000191 45         5.749514173          3272789809         4.313548823          1816631149        18.40806196        33.16342871        25.35577142
    "Congo, Dem. Rep." 2005 6.099999905 45         14.22596794          3803691856         18.18181818          2309731003        20.02244431        32.97319396        24.24951095
    "Congo, Dem. Rep." 2006 6.199999809 45         2.597530001          4297047623         8.222181619          2716544076        19.79716564        31.31528928        25.64298919
    "Congo, Dem. Rep." 2007 6.300000191 45         4.482819999          5055521502         5.098767516          3277795173        20.71154073        31.94453405        29.76939706
    "Congo, Dem. Rep." 2008 6.699999809 45         4.441200001          6574533807         2.698795181          4335835006        23.41254957         35.5010277         32.1326761
    "Congo, Dem. Rep." 2009 6.800000191 45         1.571409999  -9513066800.482039         1.908337244   591954202.4042532        25.09670993        35.09390781        33.36004505
    "Congo, Dem. Rep." 2010           6 45         8.108880001          6737172555         9.146318887          3498347635        17.85241326         34.3804565        35.32450811
    "Congo, Dem. Rep." 2011 5.900000095 45         6.947349998          7621605981         7.685564127          3968716180        17.58058702        33.76212888        38.51748277
    "Congo, Dem. Rep." 2012 6.099999905 45         8.006030003          8725734953         7.867499724          4501849079        17.35597668        33.64032195        38.76097957
    "Congo, Dem. Rep." 2013 6.300000191 45                   9          9558217689         21.41534695          5026566853        17.64731569        33.55707582        40.59346832
    "Congo, Dem. Rep." 2014 6.400000095 45         16.15189252         11418202496          -9.6985066          5566510631        17.75297526        36.41546381        37.86012765
    "Congo, Dem. Rep." 2015           6 45                 5.9         12118933629         4.787179859          5874759865        17.05328844        35.17891378        34.01657923
    "Congo, Dem. Rep." 2016 5.900000095 45              .50939         10156707783         8.645523091          5854854332        19.31944252        33.51440037 -3.130341643573461
    "Congo, Rep."      1996 26.29999924 46         6.418233928          1317167039                  .9         170266027.2        6.701546511        51.84273294        44.75377763
    "Congo, Rep."      1997 25.39999962 46         12.45618209          1320781998        -18.74999991         126784106.7        5.458434757        56.86361289        50.75829805
    "Congo, Rep."      1998 26.10000038 46         5.640611362         897870000.3         2.036198895         135604304.4        6.955916877        46.05686462         32.0502754
    "Congo, Rep."      1999 26.10000038 46         3.159227991          1442262875         -6.15163728         128634256.4          5.4647071        61.27095839        47.20744732
    "Congo, Rep."      2000 25.20000076 46          2.95133438          2323251574         13.23809524         111941932.4         3.47655398        72.15267176        62.69263159
    "Congo, Rep."      2001          26 46        -3.128131399          1829917528          23.6333053         126050678.1         4.51105795        65.48845384        49.61384357
    "Congo, Rep."      2002 26.20000076 46         1.371711266          1912227495         17.00680272         160691386.2        5.320917858        63.31892251        44.95239244
    "Congo, Rep."      2003 26.79999924 46        -3.771073647          2138505434         10.02906977         210598652.5        6.024214982        61.17235948        40.49283821
    "Congo, Rep."      2004 26.10000038 46         2.051636699          3061795456         8.454425363         231503916.1        4.980047235        65.86448408        44.63472796
    "Congo, Rep."      2005 25.89999962 46         11.29433025          4375430476         8.160779537         243427043.3        3.999127916        71.88152116        55.93675461
    "Congo, Rep."      2006        25.5 46         7.083417901          5837173050         7.995495495         276348701.2        3.574432296        75.50091525        58.74590454
    "Congo, Rep."      2007 25.29999924 46        -10.31834627          6148340321                   9           338433624        4.031521035        73.24084127        51.16704783
    "Congo, Rep."      2008 24.89999962 46         6.224441983          9180496524         6.999837369         410899558.4         3.46487139        77.41366256        53.95295882
    "Congo, Rep."      2009 25.29999924 46           12.765314          6822631237         5.500321865         428953571.9        4.471276311        71.11694931        35.65420243
    "Congo, Rep."      2010 25.20000076 46         11.57237831          9051203670                 5.8         454236720.1        3.782821809         75.3771968        49.13688848
    "Congo, Rep."      2011 25.60000038 46         -.978080558         11053714179          7.99958348         524000346.7        3.632431829        76.62564245        60.10938308
    "Congo, Rep."      2012 25.60000038 46        -3.535587439         10226671611         8.700521393         525000533.8        3.838303961        74.76768428        57.95507155
    "Congo, Rep."      2013 26.10000038 46        -3.319167534         10144053113         8.899987719         605173670.1        4.296322992        72.01590349        45.34886322
    "Congo, Rep."      2014          27 46         5.680767413          9841556183         8.953297495         671925406.8        4.739399373        69.41702863         39.1966417
    "Congo, Rep."      2015 26.20000076 46          .221011305          4676384036         10.30558495         626636762.7        7.326381826        54.67437765        23.34277804
    "Congo, Rep."      2016          26 46        -4.704725905          3932822514         -.518723575           644193453        8.223561917        50.20511976 20.076019660351207
    "Cote d'Ivoire"    1996           5 48  13.152517341689723          2478631710   12.69293568477639          1771488121 13.116208583244212 28.723328353502858        4.696614663
    "Cote d'Ivoire"    1997 5.099999905 48   8.217791593170206          2772290273  .09268688800753777          2026146993 10.937766663727972  22.34903641640857        4.312470594
    "Cote d'Ivoire"    1998 5.199999809 48  3.0925552286762246          2872739773  -2.835967470889175          2042539746 11.619413568358267 17.064187198853865        3.794842115
    "Cote d'Ivoire"    1999 5.199999809 48  19.238866445960724          2711283807    9.64241476248146          2051326695 13.211011365584024 15.602914480669293        3.336150149
    "Cote d'Ivoire"    2000 5.199999809 48  -4.473735550327081          2304639916   -22.7984573136399          1844543565  9.000695279944342   23.1682615527763        4.286963106
    "Cote d'Ivoire"    2001 5.199999809 48  1.1341445959456617          2381417893  2.6854035462701473          1808451685  8.848319103610834  32.34592036027394        3.285568754
    "Cote d'Ivoire"    2002 5.099999905 48  32.640117980727524          2605679694  14.623043502174417          1760480758 12.918910210932935 24.432534969229447        3.451776783
    "Cote d'Ivoire"    2003 4.900000095 48  14.541090089807025          3225640111 -2.9173476286129496          1885035425 14.951360782189603 35.029486334610475        3.612383218
    "Cote d'Ivoire"    2004 4.900000095 48  -8.213554725882055          3643727777 -11.059839057357099          2063557690 12.451992876916684  22.69793420831948        3.595833429
    "Cote d'Ivoire"    2005           5 48   8.906213875097082          3898241429  -5.222183868423062          2470556987 6.2976610196233676   22.8572351351801        5.471314272
    "Cote d'Ivoire"    2006 5.099999905 48 -1.1089733381052316          4188933774  -4.257530608152039          2533190053 11.666403850329239  18.44918299573928         8.04444269
    "Cote d'Ivoire"    2007 5.099999905 48   3.547397312426611          4734312913  21.986105442655195          2961423575 11.825289447906009 32.858670582221116        7.155094545
    "Cote d'Ivoire"    2008 5.099999905 48  10.966886496230655          5908708539  -4.875479984371107          3463333283 18.152782985101258 29.812933722479606         8.09462996
    "Cote d'Ivoire"    2009 5.099999905 48         3.885672864          6080678325         -.332824387          3249439893 10.929942268145016 19.044101015919725        5.538407294
    "Cote d'Ivoire"    2010 5.099999905 48        -4.003464738          5576186659         -.956501847          3141870105  15.91027850953793 23.751969583026888        6.435129731
    "Cote d'Ivoire"    2011 5.099999905 48        -7.649659256          6145942673        -11.10925052          3382474393  7.013012903135835  38.98896512573604        8.813254412
    "Cote d'Ivoire"    2012 5.099999905 48        -1.430141839          6041559792         6.754961355          3516663464  8.768725582011049 13.456212293560307        8.384066232
    "Cote d'Ivoire"    2013 5.300000191 48         28.83545941          8115685361           18.505693          3975273615        14.15581413        28.89967953        6.616992141
    "Cote d'Ivoire"    2014 5.400000095 48         4.502016543          9695648994         4.169854973          5024511239        15.86298364        30.61032488        5.543796082
    "Cote d'Ivoire"    2015         5.5 48         8.295794422          8544100135         2.815580417          4174203315        14.13094124         28.9243642        5.482997791
    "Cote d'Ivoire"    2016 5.599999905 48         15.16188392         10008719636         6.348467898          4671177463        14.38042686        30.81228701 15.478524616142792
    "Djibouti"         1996 19.79999924 55        -4.661225416         66441219.66        -3.393593833         12204522.82        2.889264829        15.72910978         .664007194
    "Djibouti"         1997 19.89999962 55        -1.805361113         66885736.63           .60007118         12587145.02        2.885037014         15.3305476         .676909113
    "Djibouti"         1998          20 55        -1.926533101         67043286.95        -4.125235478         12333939.15        2.704136391        14.69880707         .947348472
    "Djibouti"         1999 19.70000076 55         2.036144351         69789163.91        -3.946084166         12086360.08        2.578569542        14.88919834         .391087418
    "Djibouti"         2000 19.89999962 55         3.409746771         73900917.73         1.562500518         12569814.48        2.611296776        15.35243249         .382079268
    "Djibouti"         2001 19.89999962 55         5.172888395         79091947.49         3.099997942         13187524.27        2.609544763        15.65069935         .415974591
    "Djibouti"         2002 20.20000076 55         3.953569935         82738111.98         3.100002009         13682119.73        2.644072367        15.98915665         .454277724
    "Djibouti"         2003 20.60000038 55         3.205510489          87071308.4         3.102844965            14384344        2.669752345        16.16054439         .623059168
    "Djibouti"         2004 21.10000038 55         7.336301417         96370153.22         3.997132809         15428677.53        2.661283278        16.62282958         .573154706
    "Djibouti"         2005 21.20000076 55         5.360069581         104708503.8         2.500000143         16305332.52        2.585915337        16.60605974         .529249755
    "Djibouti"         2006 22.10000038 55         3.680465167           112327187         2.299996483         17258511.94        2.517069328        16.38236935         .616385692
    "Djibouti"         2007 23.20000076 55 -11.350489460657688           126180924 -3.7624361962183652         18309597.63        2.450208953        16.88565943         .523310117
    "Djibouti"         2008 23.89999962 55  -.7390001384518832 -1989830694.9143486 -10.983880339071836  3125017727.2186832 10.942029619651194  9.010936815254242         .790439022
    "Djibouti"         2009 23.79999924 55   3.731353710045605  -36902930027.02663   .5340950132140019  -6661496770.194587 17.654698657461662 -6.409151291349759         .743212074
    "Djibouti"         2010 22.89999962 55    7.31957285474453  3970653276.0069313  2.7062576684692683   7094137792.431494  5.087952552073039  24.83973709000515         .838156181
    "Djibouti"         2011          23 55  -4.419261582970957 -41041681784.756134  -5.991836861828232  -7685139312.667394 11.679204189126127  5.127204503725435          .88846349
    end
    label values country country
    label def country 33 "Cabo Verde", modify
    label def country 45 "Congo, Dem. Rep.", modify
    label def country 46 "Congo, Rep.", modify
    label def country 48 "Cote d'Ivoire", modify
    label def country 55 "Djibouti", modify
    *Generate new variable COUNTRY and replace with preferred country names*


    gen COUNTRY = country_name
    order country_name COUNTRY
    replace COUNTRY = "Cote d`Ivoire" if country_name == "Cote d'Ivoire"
    replace COUNTRY = "Cape Verde" if country_name == "Cabo Verde"
    replace COUNTRY = "Congo-Brazzaville" if country_name == "Congo, Rep."

    *output*

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str30 country_name str21 COUNTRY int year double vb_50 long country double _1_vb_22
    "Cabo Verde"       "Cote dIvoire" 1996 8.100000381 33         .699582407
    "Cabo Verde"       "Cote dIvoire" 1997 8.100000381 33         .695863673
    "Cabo Verde"       "Cote dIvoire" 1998 8.300000191 33         .706620847
    "Cabo Verde"       "Cote dIvoire" 1999 8.600000381 33         .367855417
    "Cabo Verde"       "Cote dIvoire" 2000 8.800000191 33         .414263908
    "Cabo Verde"       "Cote dIvoire" 2001 8.699999809 33         .396626069
    "Cabo Verde"       "Cote dIvoire" 2002 9.300000191 33         .447182205
    "Cabo Verde"       "Cote dIvoire" 2003 8.899999619 33         .615835443
    "Cabo Verde"       "Cote dIvoire" 2004 9.199999809 33         .513253874
    "Cabo Verde"       "Cote dIvoire" 2005 9.899999619 33         .496661145
    "Cabo Verde"       "Cote dIvoire" 2006        10.5 33         .425894536
    "Cabo Verde"       "Cote dIvoire" 2007 11.10000038 33         .489084652
    "Cabo Verde"       "Cote dIvoire" 2008 11.60000038 33         .478993182
    "Cabo Verde"       "Cote dIvoire" 2009 11.69999981 33         .544044637
    "Cabo Verde"       "Cote dIvoire" 2010 11.30000019 33         .488298295
    "Cabo Verde"       "Cote dIvoire" 2011 11.39999962 33         .504031768
    "Cabo Verde"       "Cote dIvoire" 2012 10.89999962 33         .631569353
    "Cabo Verde"       "Cote dIvoire" 2013 11.10000038 33         .616474913
    "Cabo Verde"       "Cote dIvoire" 2014 11.19999981 33          .63743089
    "Cabo Verde"       "Cote dIvoire" 2015 11.19999981 33          .97317191
    "Cabo Verde"       "Cote dIvoire" 2016 11.39999962 33 -.6768793574430525
    "Congo, Dem. Rep." "Cote dIvoire" 1996         4.5 45        37.42208798
    "Congo, Dem. Rep." "Cote dIvoire" 1997 4.599999905 45        33.03761611
    "Congo, Dem. Rep." "Cote dIvoire" 1998 4.699999809 45         32.4023271
    "Congo, Dem. Rep." "Cote dIvoire" 1999           4 45        28.80415077
    "Congo, Dem. Rep." "Cote dIvoire" 2000         4.5 45        7.636860145
    "Congo, Dem. Rep." "Cote dIvoire" 2001 5.599999905 45        18.51487867
    "Congo, Dem. Rep." "Cote dIvoire" 2002 6.099999905 45        18.84967793
    "Congo, Dem. Rep." "Cote dIvoire" 2003 5.699999809 45        29.72276229
    "Congo, Dem. Rep." "Cote dIvoire" 2004 5.800000191 45        25.35577142
    "Congo, Dem. Rep." "Cote dIvoire" 2005 6.099999905 45        24.24951095
    "Congo, Dem. Rep." "Cote dIvoire" 2006 6.199999809 45        25.64298919
    "Congo, Dem. Rep." "Cote dIvoire" 2007 6.300000191 45        29.76939706
    "Congo, Dem. Rep." "Cote dIvoire" 2008 6.699999809 45         32.1326761
    "Congo, Dem. Rep." "Cote dIvoire" 2009 6.800000191 45        33.36004505
    "Congo, Dem. Rep." "Cote dIvoire" 2010           6 45        35.32450811
    "Congo, Dem. Rep." "Cote dIvoire" 2011 5.900000095 45        38.51748277
    "Congo, Dem. Rep." "Cote dIvoire" 2012 6.099999905 45        38.76097957
    "Congo, Dem. Rep." "Cote dIvoire" 2013 6.300000191 45        40.59346832
    "Congo, Dem. Rep." "Cote dIvoire" 2014 6.400000095 45        37.86012765
    "Congo, Dem. Rep." "Cote dIvoire" 2015           6 45        34.01657923
    "Congo, Dem. Rep." "Cote dIvoire" 2016 5.900000095 45 -3.130341643573461
    "Congo, Rep."      "Cote dIvoire" 1996 26.29999924 46        44.75377763
    "Congo, Rep."      "Cote dIvoire" 1997 25.39999962 46        50.75829805
    "Congo, Rep."      "Cote dIvoire" 1998 26.10000038 46         32.0502754
    "Congo, Rep."      "Cote dIvoire" 1999 26.10000038 46        47.20744732
    "Congo, Rep."      "Cote dIvoire" 2000 25.20000076 46        62.69263159
    "Congo, Rep."      "Cote dIvoire" 2001          26 46        49.61384357
    "Congo, Rep."      "Cote dIvoire" 2002 26.20000076 46        44.95239244
    "Congo, Rep."      "Cote dIvoire" 2003 26.79999924 46        40.49283821
    "Congo, Rep."      "Cote dIvoire" 2004 26.10000038 46        44.63472796
    "Congo, Rep."      "Cote dIvoire" 2005 25.89999962 46        55.93675461
    "Congo, Rep."      "Cote dIvoire" 2006        25.5 46        58.74590454
    "Congo, Rep."      "Cote dIvoire" 2007 25.29999924 46        51.16704783
    "Congo, Rep."      "Cote dIvoire" 2008 24.89999962 46        53.95295882
    "Congo, Rep."      "Cote dIvoire" 2009 25.29999924 46        35.65420243
    "Congo, Rep."      "Cote dIvoire" 2010 25.20000076 46        49.13688848
    "Congo, Rep."      "Cote dIvoire" 2011 25.60000038 46        60.10938308
    "Congo, Rep."      "Cote dIvoire" 2012 25.60000038 46        57.95507155
    "Congo, Rep."      "Cote dIvoire" 2013 26.10000038 46        45.34886322
    "Congo, Rep."      "Cote dIvoire" 2014          27 46         39.1966417
    "Congo, Rep."      "Cote dIvoire" 2015 26.20000076 46        23.34277804
    "Congo, Rep."      "Cote dIvoire" 2016          26 46 20.076019660351207
    "Cote d'Ivoire"    "Cote dIvoire" 1996           5 48        4.696614663
    "Cote d'Ivoire"    "Cote dIvoire" 1997 5.099999905 48        4.312470594
    "Cote d'Ivoire"    "Cote dIvoire" 1998 5.199999809 48        3.794842115
    "Cote d'Ivoire"    "Cote dIvoire" 1999 5.199999809 48        3.336150149
    "Cote d'Ivoire"    "Cote dIvoire" 2000 5.199999809 48        4.286963106
    "Cote d'Ivoire"    "Cote dIvoire" 2001 5.199999809 48        3.285568754
    "Cote d'Ivoire"    "Cote dIvoire" 2002 5.099999905 48        3.451776783
    "Cote d'Ivoire"    "Cote dIvoire" 2003 4.900000095 48        3.612383218
    "Cote d'Ivoire"    "Cote dIvoire" 2004 4.900000095 48        3.595833429
    "Cote d'Ivoire"    "Cote dIvoire" 2005           5 48        5.471314272
    "Cote d'Ivoire"    "Cote dIvoire" 2006 5.099999905 48         8.04444269
    "Cote d'Ivoire"    "Cote dIvoire" 2007 5.099999905 48        7.155094545
    "Cote d'Ivoire"    "Cote dIvoire" 2008 5.099999905 48         8.09462996
    "Cote d'Ivoire"    "Cote dIvoire" 2009 5.099999905 48        5.538407294
    "Cote d'Ivoire"    "Cote dIvoire" 2010 5.099999905 48        6.435129731
    "Cote d'Ivoire"    "Cote dIvoire" 2011 5.099999905 48        8.813254412
    "Cote d'Ivoire"    "Cote dIvoire" 2012 5.099999905 48        8.384066232
    "Cote d'Ivoire"    "Cote dIvoire" 2013 5.300000191 48        6.616992141
    "Cote d'Ivoire"    "Cote dIvoire" 2014 5.400000095 48        5.543796082
    "Cote d'Ivoire"    "Cote dIvoire" 2015         5.5 48        5.482997791
    "Cote d'Ivoire"    "Cote dIvoire" 2016 5.599999905 48 15.478524616142792
    "Djibouti"         "Cote dIvoire" 1996 19.79999924 55         .664007194
    "Djibouti"         "Cote dIvoire" 1997 19.89999962 55         .676909113
    "Djibouti"         "Cote dIvoire" 1998          20 55         .947348472
    "Djibouti"         "Cote dIvoire" 1999 19.70000076 55         .391087418
    "Djibouti"         "Cote dIvoire" 2000 19.89999962 55         .382079268
    "Djibouti"         "Cote dIvoire" 2001 19.89999962 55         .415974591
    "Djibouti"         "Cote dIvoire" 2002 20.20000076 55         .454277724
    "Djibouti"         "Cote dIvoire" 2003 20.60000038 55         .623059168
    "Djibouti"         "Cote dIvoire" 2004 21.10000038 55         .573154706
    "Djibouti"         "Cote dIvoire" 2005 21.20000076 55         .529249755
    "Djibouti"         "Cote dIvoire" 2006 22.10000038 55         .616385692
    "Djibouti"         "Cote dIvoire" 2007 23.20000076 55         .523310117
    "Djibouti"         "Cote dIvoire" 2008 23.89999962 55         .790439022
    "Djibouti"         "Cote dIvoire" 2009 23.79999924 55         .743212074
    "Djibouti"         "Cote dIvoire" 2010 22.89999962 55         .838156181
    "Djibouti"         "Cote dIvoire" 2011          23 55          .88846349
    end
    label values country country
    label def country 33 "Cabo Verde", modify
    label def country 45 "Congo, Dem. Rep.", modify
    label def country 46 "Congo, Rep.", modify
    label def country 48 "Cote d'Ivoire", modify
    label def country 55 "Djibouti", modify


    What am i doing wrong?

  • #2
    Johnny;
    the devil rests in "Cote d`Ivoire", as you can see from the following toy-example, in which "Cote d`Ivoire" was cautiously replaced with "A":
    Code:
    . gen COUNTRYbis = country_name
     tab country_name
    
                      country_name |      Freq.     Percent        Cum.
    -------------------------------+-----------------------------------
                        Cabo Verde |         21       21.00       21.00
                  Congo, Dem. Rep. |         21       21.00       42.00
                       Congo, Rep. |         21       21.00       63.00
                     Cote d'Ivoire |         21       21.00       84.00
                          Djibouti |         16       16.00      100.00
    -------------------------------+-----------------------------------
                             Total |        100      100.00
    
    . replace COUNTRYbis="A" if country_name=="Cote d'Ivoire"
    (21 real changes made)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      I'm not sure that I follow what's going on, but maybe try replacing the line of code
      Code:
      replace COUNTRY = "Cote d`Ivoire" if country_name == "Cote d'Ivoire"
      with
      Code:
      replace COUNTRY = "Cote d\`Ivoire" if country_name == "Cote d'Ivoire"

      Comment


      • #4
        I agree with Carlo, but I can't explain why.

        We can simplify the example and show a work-around. In fact, the repetitions aren't needed here to show the problem. I pepper the code with uses of


        Code:
        groups *
        where groups is from the Stata Journal; see

        SJ-17-3 st0496 . . . . . Speaking Stata: Tables as lists: The groups command
        (help groups if installed) . . . . . . . . . . . . . . . . N. J. Cox
        Q3/17 SJ 17(3):760--773
        presents command for listing group frequencies and percents and
        cumulations thereof; for various subsetting and ordering by
        frequencies, percents, and so on; for reordering of columns;
        and for saving tabulated data to new datasets

        or https://www.statalist.org/forums/for...updated-on-ssc

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input str30 country_name long country
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Cabo Verde"       33
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Dem. Rep." 45
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Congo, Rep."      46
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Cote d'Ivoire"    48
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        "Djibouti"         55
        end
        label values country country
        label def country 33 "Cabo Verde", modify
        label def country 45 "Congo, Dem. Rep.", modify
        label def country 46 "Congo, Rep.", modify
        label def country 48 "Cote d'Ivoire", modify
        label def country 55 "Djibouti", modify
        
        . gen COUNTRY = country_name
        
        . groups *
        
          +--------------------------------------------------------------------------+
          |     country_name            country            COUNTRY   Freq.   Percent |
          |--------------------------------------------------------------------------|
          |       Cabo Verde         Cabo Verde         Cabo Verde      21     21.00 |
          | Congo, Dem. Rep.   Congo, Dem. Rep.   Congo, Dem. Rep.      21     21.00 |
          |      Congo, Rep.        Congo, Rep.        Congo, Rep.      21     21.00 |
          |    Cote d'Ivoire      Cote d'Ivoire      Cote d'Ivoire      21     21.00 |
          |         Djibouti           Djibouti           Djibouti      16     16.00 |
          +--------------------------------------------------------------------------+
        
        . order country_name COUNTRY
        
        . count if country_name == "Cote d'Ivoire"
          21
        
        . replace COUNTRY = "Cote d" + "`" + "Ivoire" if country_name == "Cote d'Ivoire"
        (21 real changes made)
        
        . groups *
        
          +--------------------------------------------------------------------------+
          |     country_name            COUNTRY            country   Freq.   Percent |
          |--------------------------------------------------------------------------|
          |       Cabo Verde         Cabo Verde         Cabo Verde      21     21.00 |
          | Congo, Dem. Rep.   Congo, Dem. Rep.   Congo, Dem. Rep.      21     21.00 |
          |      Congo, Rep.        Congo, Rep.        Congo, Rep.      21     21.00 |
          |    Cote d'Ivoire      Cote d`Ivoire      Cote d'Ivoire      21     21.00 |
          |         Djibouti           Djibouti           Djibouti      16     16.00 |
          +--------------------------------------------------------------------------+
        I tend to avoid the back-tick or left quotation mark character ` in string variable contents if only because of its role in local macro references. It clearly messes up the management here. I am tempted to call this a bug, dangerous though that always is if you see a problem but don't understand it. Segregating the character as above avoids the problem.

        Comment


        • #5
          Thank you very much. That worked.

          Comment


          • #6
            It looks like Stata's parser is gobbling up everything from the left single quote to the right single quote in search of a local macro to expand. What's in between these single quotes is not a valid local macro name and therefore expands to nothing. Since macro expansion never generates an error, execution goes on. Here's a reduced example that shows variations on the theme:
            Code:
            * Example generated by -dataex-. To install: ssc install dataex
            clear
            input str30 country_name
            "Cabo Verde"      
            "Congo, Dem. Rep."
            "Congo, Rep."    
            "Cote d'Ivoire"  
            "Djibouti"        
            end
            
            * Stata tries to expand `Ivoire" if country_name == "Cote d'
            gen case1 = country_name
            replace case1 = "Cote d`Ivoire" if country_name == "Cote d'Ivoire"
            
            * no matching single quotes if you separate the condition
            gen target = country_name == "Cote d'Ivoire"
            gen case2 = country_name
            replace case2 = "Cote d`Ivoire" if target
            
            * no matching single quote here
            gen case3 = country_name
            replace case3 = "what now" if country_name == "Cote d'Ivoire"
            
            * replace is not at fault here
            gen case4 = "Cote d`Ivoire" if country_name == "Cote d'Ivoire"
            list
            and the list results
            Code:
            . list
            
                 +-----------------------------------------------------------------------------------------------+
                 |     country_name          case1   target              case2              case3          case4 |
                 |-----------------------------------------------------------------------------------------------|
              1. |       Cabo Verde   Cote dIvoire        0         Cabo Verde         Cabo Verde   Cote dIvoire |
              2. | Congo, Dem. Rep.   Cote dIvoire        0   Congo, Dem. Rep.   Congo, Dem. Rep.   Cote dIvoire |
              3. |      Congo, Rep.   Cote dIvoire        0        Congo, Rep.        Congo, Rep.   Cote dIvoire |
              4. |    Cote d'Ivoire   Cote dIvoire        1      Cote d`Ivoire           what now   Cote dIvoire |
              5. |         Djibouti   Cote dIvoire        0           Djibouti           Djibouti   Cote dIvoire |
                 +-----------------------------------------------------------------------------------------------+
            
            .
            As a side note, the correct character for an apostrophe is the right single quote so it's wrong to try to replace "Cote d'Ivoire" with "Cote d`Ivoire" (presumably because it looks a bit like a curly apostrophe).
            Last edited by Robert Picard; 29 Mar 2018, 08:49.

            Comment

            Working...
            X