Announcement

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

  • Need help to create a new dataset

    I need extract the data for the countries in sub-saharan and selected countries in asia and latin america. I used the code below but got the error message that the code is too long:

    egen sub_saharan = inlist(country, "Angola", "Benin", "Botswana", "Burkina Faso", "Burundi", "Cabo Verde", "Cameroon", "Central African Republic", "Chad", "Comoros", "Congo", "Cote d'Ivoire", "Democratic Republic of Congo", "Djibouti", "Equatorial Guinea", "Eritrea", "Eswatini", "Ethiopia", "Gabon", "Gambia", "Ghana", "Guinea", "Guinea-Bissau", "Kenya", "Lesotho", "Liberia", "Madagascar", "Malawi", "Mali", "Mauritania", "Mauritius", "Mozambique", "Namibia", "Niger", "Nigeria", "Rwanda", "Sao Tome and Principe", "Senegal", "Seychelles", "Sierra Leone", "Somalia", "South Africa", "South Sudan", "Sudan", "Tanzania", "Togo", "Uganda", "Zambia", "Zimbabwe")

    Need help to code it.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str52 countryname double(MANU_2000 MANU_2020 GDP_2000 GDP_2020) byte _merge float(manu_share_gdp_2000 manu_share_gdp_2020 change change_)
    "mexico"                                                         . 1546262359.6263392                  . 20143442150.971035 3         .  7.676257          .          .
    "Africa Eastern and Southern"                    41592887212.81602  96469746317.05486  283928427609.5787  927484450967.3069 3 14.649075 10.401225   -40.8399 -4.2478495
    "mexico"                                         17673119181.70438  93693461398.49365 140410259302.46503  784799699387.3774 3 12.586772  11.93852  -5.429924  -.6482525
    "Albania"                                        150276373.5348036  913668707.7772664 3480355258.0412197 15131866270.593649 3  4.317846  6.038044   28.48933   1.720198
    "Algeria"                                       24644936606.262573 27297857336.673588 54790392746.193855 145009181490.61975 3   44.9804 18.824917 -138.94075  -26.15548
    "American Samoa"                                                 .          1.090e+08                  .          7.160e+08 3         . 15.223464          .          .
    "Andorra"                                        54744794.54578958 107938320.95945175 1429049198.4521837  2891022272.986865 3 3.8308544 3.7335694  -2.605684 -.09728503
    "Angola"                                        263860200.80418858 3704705929.1503468  9129594818.607492 53619073505.137726 3 2.8901634  6.909306   58.16999  4.0191426
    "Antigua and Barbuda"                           13481481.481481481 33307407.407407407  826370370.3703703 1370281481.4814813 3  1.631409  2.430698   32.88311   .7992891
    "Arab World"                                     98365266476.99477  288989505581.4489  816019292861.1843 2490805099290.1396 3 12.054282 11.602253  -3.896047  -.4520292
    "Argentina"                                            46877339400  55391122541.79237       284203750000  385540224628.2918 3 16.494272 14.367145   -14.8055 -2.1271276
    "Armenia"                                                        . 1560606156.6568625 1911563668.8500648 12641697523.296612 3         .  12.34491          .          .
    "Aruba"                                          76829608.93854748                  . 1873184357.5418994  2610038937.563553 3  4.101551         .          .          .
    "Australia"                                      48082019719.90202  74662823434.77678 415851284305.72125 1326901059123.2068 3  11.56231  5.626857 -105.48437  -5.935454
    "Austria"                                        35936240321.64713  71428570042.59943  197289625479.9063   435225238000.437 3 18.214968 16.411863  -10.98659 -1.8031044
    "Azerbaijan"                                     279056772.4631202  2604941176.470588  5272798390.701833         4.2693e+10 3  5.292385  6.101565  13.261848   .8091803
    "Bahamas, The"                                           2.332e+08          1.350e+08         8076470000         9.6995e+09 3    2.8874 1.3918244 -107.45435 -1.4955758
    "Bahrain"                                                        .  6294815159.574468  9062898936.170212  34723357446.80851 3         . 18.128475          .          .
    "Bangladesh"                                     7490618167.362353   77017599101.8243  53369787318.62453  373902134700.4096 3 14.035316  20.59833   31.86188   6.563016
    "Barbados"                                               2.369e+08          228350000         3.0595e+09         4.6718e+09 3  7.743095  4.887838  -58.41555 -2.8552575
    "Belarus"                                       3444492987.6727004 13186587965.240204 12736856827.984661  61371126414.16626 3  27.04351  21.48663  -25.86202  -5.556877
    "Belgium"                                        41523865340.07852  64558637371.98461  236792460312.4711 525211810652.60846 3 17.535975 12.291924  -42.66256   -5.24405
    "Belize"                                                 107644400          151575900          1.116e+09          2.080e+09 3  9.645555  7.287303 -32.361115 -2.3582525
    "Benin"                                           492230578.788186 1516193919.1721148  3519991326.484636 15651545208.878334 3 13.983858  9.687183  -44.35422 -4.2966747
    "Bermuda"                                                        .           23167000         3480219000         6887147000 3         .  .3363802          .          .
    "Bhutan"                                         36022583.44459279 137679960.48561665  424464089.8976413    2325184481.4277 3  8.486604  5.921249  -43.32456  -2.565355
    "Bolivia"                                        1111976485.809008  4013837354.164153   8397912525.26886  36629843805.02156 3 13.241106 10.957833   -20.8369 -2.2832727
    "Bosnia and Herzegovina"                        517547291.56853503 2616331391.9627256  5567405605.275553 19950471170.646477 3  9.296022 13.114133   29.11447  3.8181105
    "Botswana"                                       325708573.4446666  846611355.4470434  5788329609.157553 14930072458.581379 3  5.626987  5.670511   .7675378  .04352331
    "Brazil"                                         86090888322.87697  139980408073.4016  655448188237.3712 1448559976218.1875 3  13.13466  9.663418  -35.92147  -3.471242
    "British Virgin Islands"                                         .                  .                  .                  . 3         .         .          .          .
    "Brunei Darussalam"                               921964211.136891 1893301732.2606366  6001153306.264502  12005825759.22302 3 15.363117 15.769858  2.5792315   .4067411
    "Bulgaria"                                                       .                  . 13245834314.510431  70240275010.19635 3         .         .          .          .
    "Burkina Faso"                                  455850762.31188613 1668287721.3830774 2968369991.4672885 17933606353.177456 3 15.356938  9.302578  -65.08261   -6.05436
    "Burundi"                                        94893712.37875865                  .  870486065.8831366  2649671998.861917 3 10.901233         .          .          .
    "Cabo Verde"                                    49948220.819119185 125172576.88099782  539227277.6264108 1703698676.6974154 3  9.262925  7.347108   -26.0758 -1.9158173
    "Cambodia"                                       585041601.5827712 4192339971.7336607 3654031716.2688117 25872798012.193756 3  16.01085  16.20366   1.189905  .19280815
    "Cameroon"                                      1557542197.4970713  5374315914.563593 10566578952.785664  40773241531.23946 3  14.74027 13.180987 -11.829783 -1.5592823
    "Canada"                                         126793481920.4094                  .   744773415931.587 1645423407568.3633 3 17.024437         .          .          .
    "Caribbean small states"                                         .  5932627019.158538  34533832084.89896  65896805290.32859 3         .  9.002905          .          .
    "Cayman Islands"                                                 .  51007920.31681267                  .  5608989199.567983 3         .  .9093959          .          .
    "Central African Republic"                                       .  412458435.7506958  916777282.6511683 2326720920.5922313 3         . 17.727026          .          .
    "Central Europe and the Baltics"                  78469593305.4127 280169875597.78735  428275378877.5333 1664902507747.8442 3  18.32223 16.828005  -8.879393 -1.4942245
    "Chad"                                          119246192.10146888  341981910.6093616 1388506726.6209335 10715396135.416775 3  8.588089 3.1915004 -169.09253  -5.396588
    "Channel Islands"                                                .                  .  6439403014.003704                  . 3         .         .          .          .
    "Chile"                                         11888134541.647465  22511798703.32606   78249883995.6255 252727193710.01776 3 15.192527  8.907549 -70.557884  -6.284978
    "China"                                                          .   3860679921168.56 1211346869605.2378 14687673892881.984 3         .  26.28517          .          .
    "Colombia"                                       13916897812.63671 29386816876.984158  99886577330.72711 270299984937.97015 3   13.9327 10.871927    -28.153  -3.060774
    "Comoros"                                                        .                  .  351136568.4419213 1225039230.7408347 3         .         .          .          .
    "Congo, Dem. Rep."                               1891304347.826087  9251949921.566496   19088046305.7971   48716960860.0664 3  9.908319  18.99123   47.82687  9.0829115
    "Congo, Rep."                                   112220648.84872445                  . 3227927697.4366474 10483151175.845139 3  3.476554         .          .          .
    "Costa Rica"                                    2750128099.8734546  7910531292.224033  15013629658.65213 62158002233.027855 3 18.317543  12.72649  -43.93242  -5.591054
    "Cote d'Ivoire"                                  1849136171.797558  6868470185.341547 16577533355.439533 61348579465.101654 3  11.15447  11.19581   .3692271  .04133797
    "Croatia"                                        3637623994.831995  6933574435.382346 21807856145.103745 57472012426.685265 3 16.680338 12.064262  -38.26239 -4.6160755
    "Cuba"                                                  5.0197e+09          1.202e+10        3.05654e+10        1.07352e+11 3 16.422817  11.19681  -46.67406  -5.226007
    "Curacao"                                                        .  102617318.4357542                  .  2496174748.603352 3         .  4.110983          .          .
    "Cyprus"                                         813785108.3883129 1418500285.5511138  9985844486.333649  25008448886.35066 3  8.149387  5.672084  -43.67536  -2.477303
    "Czechia"                                        14453887111.19172  52520804385.99326   61828166496.0941 245974558654.04294 3  23.37751  21.35213  -9.485625  -2.025383
    "Denmark"                                       23220007051.749947  46859678655.09934 164158739097.62344 355222449505.21106 3  14.14485 13.191644  -7.225832  -.9532061
    "Djibouti"                                                       . 140947936.37217885  551230861.8565054  3181071153.662201 3         . 4.4308324          .          .
    "Dominica"                                       22892592.59259259 14555555.555555554  333470370.3703703  504214814.8148148 3  6.864955  2.886777 -137.80695  -3.978179
    "Dominican Republic"                             5098090331.551463 11389164102.291925 24305717541.637054  78844702329.07854 3  20.97486  14.44506  -45.20439  -6.529801
    "Early-demographic dividend"                     579986457701.8035 1795380394269.9448 3386373612180.9766  10849641857292.91 3 17.127066  16.54783 -3.5003686  -.5792351
    "East Asia & Pacific"                                            .  6236691752856.254  8374985727131.451  27127309724583.31 3         . 22.990454          .          .
    "East Asia & Pacific (IDA & IBRD countries)"                     .  4445335686288.731 1732073445619.5369 17464369876211.701 3         . 25.453743          .          .
    "East Asia & Pacific (excluding high income)"                    .  4449446255121.288 1734674377491.7842 17486916629390.627 3         .  25.44443          .          .
    "Ecuador"                                       4101641820.9104557        16392070000  18327764882.44122        99291124000 3  22.37939   16.5091 -35.557896  -5.870289
    "Egypt, Arab Rep."                              17968912373.403786   59819586681.2227  99838543960.07632  365252651278.8521 3  17.99797 16.377592  -9.893875 -1.6203785
    "El Salvador"                                           2301934400         3666670000        11784927700        24563020000 3  19.53287 14.927603 -30.850664 -4.6052647
    "Equatorial Guinea"                                              . 2029847842.0253446 1045998496.4387157 10099158074.727322 3         .  20.09918          .          .
    "Eritrea"                                        65745454.54545455                  .  706370815.5844156                  . 3  9.307499         .          .          .
    "Estonia"                                        879553118.9532849  4026079092.199233  5686579747.535244 31370395572.765846 3 15.467173 12.834008 -20.517086 -2.6331644
    "Eswatini"                                        588594037.292141 1056266692.1671128 1738100853.0505202   3982226055.38454 3 33.864204  26.52453  -27.67128  -7.339676
    "Ethiopia"                                      462006283.67349446  5709392031.135356 8242392103.6806135 107657734392.44585 3  5.605245  5.303281  -5.693914  -.3019643
    "Euro area"                                     1131451579979.7598 1904806822677.7168  6495755148668.912 13085484520637.535 3 17.418322  14.55664 -19.658947  -2.861682
    "Europe & Central Asia"                          1691631816140.933 3087792147413.5337 10065982507646.672 22139980728586.813 3 16.805431  13.94668 -20.497726  -2.858752
    "Europe & Central Asia (IDA & IBRD countries)"                   .  594722171704.4205  894229330968.6034  3891716780502.407 3         . 15.281743          .          .
    "Europe & Central Asia (excluding high income)"                  . 448826475040.83856  662873791578.5691 2982626888407.6567 3         . 15.048026          .          .
    "European Union"                                1273942457682.7644 2251904608870.9253   7276322325124.59  15369441264656.69 3 17.508055 14.651832 -19.493967  -2.856223
    "Faroe Islands"                                  70208212.19581597 224316351.01878604 1067115339.4118593  3248696901.606518 3  6.579252   6.90481   4.714941   .3255577
    "Fiji"                                            205973879.545241 489589155.91532177 1678239218.2655265  4477040340.452265 3 12.273213 10.935554  -12.23221   -1.33766
    "Finland"                                       30433957102.745163  38746718603.89116  126019543413.3336 271891788362.64667 3  24.15019 14.250787  -69.46565  -9.899402
    "Fragile and conflict affected situations"                       .                  . 525774255418.92474 1670522192878.4514 3         .         .          .          .
    "France"                                        197711273080.78473  244567030848.2497 1365639660792.1597 2639008701648.2563 3 14.477558  9.267383  -56.22057  -5.210176
    "French Polynesia"                                               .                  .  3599846538.856263   5709421968.74051 3         .         .          .          .
    "Gabon"                                          189240335.2257367  2822387035.939884  5080483463.999279 15314577167.821096 3  3.724849 18.429415   79.78857  14.704566
    "Gambia, The"                                    52977470.36191311 47358943.491185725  782915402.4210955   1812169483.72578 3  6.766692  2.613384 -158.92453  -4.153308
    "Georgia"                                        374399190.4882368 1480569540.4701416 3057475335.1884646 15842922532.720198 3  12.24537  9.345305 -31.032324 -2.9000654
    "Germany"                                        400231796704.3146  727552650890.2744 1947981991011.7688 3889668895299.6216 3  20.54597 18.704744  -9.843634 -1.8412266
    "Ghana"                                          449311800.3303358  7671870793.645121  4983024408.148284  70043199813.68854 3 9.0168495 10.953055  17.677313   1.936206
    "Gibraltar"                                                      .                  .                  .                  . 3         .         .          .          .
    "Greece"                                        12383868175.421204 16473948162.594599 130457756628.43636 188925995936.80673 3  9.492627  8.719789  -8.863043  -.7728386
    "Greenland"                                                      .  105761147.0322985 1068030829.7559105  3076015346.754101 3         . 3.4382515          .          .
    "Grenada"                                        23582111.11111111 32648148.148148146  520044370.3703703 1043414814.8148147 3 4.5346346  3.128971  -44.92414 -1.4056635
    "Guam"                                                           .                  .                  .          5.886e+09 3         .         .          .          .
    "Guatemala"                                     2540511374.1755977 10958892640.221712 19288827158.903545  77625486978.25609 3 13.170896 14.117647   6.706157   .9467516
    "Guinea"                                         113086724.3175923 1378396336.0712152 2995361140.6321673  14177835816.27767 3 3.7753954  9.722192   61.16724   5.946796
    "Guinea-Bissau"                                                  .                  . 371095510.04776067 1431758242.9037538 3         .         .          .          .
    "Guyana"                                        18823658.389519267 232201438.84892085  712667896.7275119   5471256594.72422 3 2.6412945  4.244024   37.76438  1.6027293
    "Haiti"                                          887741756.4495907   2558927192.11172  6813577558.176276 14508218017.403208 3  13.02901 17.637777  26.130087  4.6087666
    end
    label values _merge _merge
    label def _merge 3 "Matched (3)", modify

  • #2
    there are a couple of issues here: first, the inlist() function does not work with -egen- but does work with -gen-; second, when the arguments are strings, as here, you are limited in the number you can use to a total of no more than 10; see
    Code:
    h inlist()
    so, I see 2 ways to go: either break your list into several smaller lists (and use "or" (|)) between the lists, or make a new data set that only has the names you want and merge it with you major data set, keeping only the matches

    Comment


    • #3
      The error message you are getting arises because -inlist()- only allows a total of 10 string arguments. (For numeric arguments the limit is much larger.) So you have to break that up into a bunch of -inlist()- terms connected by logical or (|). However, once you fix that, you will get another error message, because -inlist()- is not an -egen- function, it is a -gen- function. So:
      Code:
      gen sub_saharan = inlist(country, "Angola", "Benin", "Botswana", ///
          "Burkina Faso", "Burundi", "Cabo Verde", "Cameroon", ///
          "Central African Republic", "Chad") | inlist(country,  "Comoros", ///
          "Congo", "Cote d'Ivoire", "Democratic Republic of Congo", "Djibouti", ///
          "Equatorial Guinea", "Eritrea", "Eswatini", "Ethiopia") | ///
          inlist(country, "Gabon", "Gambia", "Ghana", "Guinea", "Guinea-Bissau", ///
          "Kenya", "Lesotho", "Liberia", "Madagascar") | inlist(country, "Malawi", ///
          "Mali", "Mauritania", "Mauritius", "Mozambique", "Namibia", "Niger", ///
          "Nigeria", "Rwanda") | inlist(country, "Sao Tome and Principe", "Senegal", ///
          "Seychelles", "Sierra Leone", "Somalia", "South Africa", "South Sudan", ///
          "Sudan", "Tanzania") | inlist(country, "Togo", "Uganda", "Zambia", "Zimbabwe")
      That will get you past Stata's parser without error messages. But then you have another problem: your code is not correctly identifying sub-Saharan countries. In your own data example, it fails to pick up "Congo, Rep." and "Congo, Dem. Rep." It misses those because your code is looking, instead, for "Congo" and "Democratic Republic of Congo", neither of which appears in your example data. This is a difficulty often encountered working with country names: there are often variants. You can generate a list of the country names that actually occur in your data and then modify your -inlist()- expressions accordingly. Or, you might find the -kountry- program, by Rafal Raciborski, available from SSC of Stata Journal (-findit kountry-) helpful here, to standardize the country names, or, better, bring ISO codes into your data set instead.

      Added: Crossed with #2.

      Comment


      • #4
        thank you, it worked. Had to cross-checked to make sure the names of the countries are the same for the datasets.

        Comment

        Working...
        X