Announcement

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

  • Please Help Convert Country Code

    Good day ,
    I am working on trade data set from BACI ( about 3 million observations )which reports countrys in UN CODE( Numbers e.g 004). I am interested to convert/replace the UN CODE to ISO3 Alpha ( Alphabet).For example , convert "124"to "CAN"

    Sample data set
    Start---------------------------------------------------------------------
    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    Year Hs UNCODE UNCODE values qty
    "2003" "10511" "004" "788" "37498" "0,583"
    "2003" "10620" "004" "392" "74361" "0,226"

    "2003" "731822" "124" "862" "16032" "2293"
    "2003" "731823" "124" "392" "2339" "0,376"

    "2003" "852439" "156" "860" "2641" "0,023"

    -----------------------------------------------------------------------end

    The code i wrote is given below:

    Code:
    gen siso=.-
    
    replace siso= CAN if UNCODE=="124"
    getting this output:

    .
    replace siso= CAN if UNCODE=="124"
    type mismatch
    r(109);
    what can i do to solve this issue

    Regards

  • #2

    Code:
    replace siso= "CAN" if UNCODE=="124"

    Comment


    • #3
      Thank you Nick Cox. Your code solved the issue.

      Comment


      • #4
        Dear Niran, You might want to check (ssc install) -kountry- to see if it helps.
        Ho-Chuan (River) Huang
        Stata 17.0, MP(4)

        Comment

        Working...
        X