Announcement

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

  • converting from one currency to another

    Hi Statalist,

    I have two variables, one that recorded monthly income and second that identifies the currency of income. I would like to convert monthly income into GBP. I am not sure how to do this.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long(m_salary currency)
      . .
      . .
    214 3
      . .
      . .
      . .
      . .
      . .
      . .
      . .
      . .
      . .
      . .
     93 3
      5 4
      . .
      . .
    129 6
      . .
    109 4
    211 4
      . .
    144 3
     17 2
      . .
     10 2
     59 4
     70 4
      . .
      . .
     30 3
      . .
      . .
      5 4
      . .
    205 4
      . .
    147 4
      . .
     87 4
      . .
     82 3
      6 3
      . .
      . .
      . .
      . .
    130 4
      . .
    160 3
    172 3
      . .
      . .
      . .
     31 2
      . .
      . .
     69 4
      . .
      . .
      . .
     87 4
    137 2
     77 4
      . .
      . .
      . .
      . .
      . .
      . .
      . .
    114 2
      . .
    150 4
      . .
      . .
      . .
    114 2
      . .
    114 2
      . .
      . .
      . .
     82 3
      . .
      . .
      . .
      . .
      . .
    113 4
      . .
      5 3
      . .
    135 3
      . .
      . .
      . .
      . .
      . .
      . .
    end
    label values m_salary m_salary
    label def m_salary 5 "1000", modify
    label def m_salary 6 "10000", modify
    label def m_salary 10 "105000", modify
    label def m_salary 17 "1200000", modify
    label def m_salary 30 "1500", modify
    label def m_salary 31 "15000", modify
    label def m_salary 59 "2500", modify
    label def m_salary 69 "27000", modify
    label def m_salary 70 "2800", modify
    label def m_salary 77 "2916", modify
    label def m_salary 82 "3000", modify
    label def m_salary 87 "3200", modify
    label def m_salary 93 "3500", modify
    label def m_salary 109 "4000", modify
    label def m_salary 113 "4100", modify
    label def m_salary 114 "41000", modify
    label def m_salary 129 "46073 NOK", modify
    label def m_salary 130 "4666", modify
    label def m_salary 135 "5000", modify
    label def m_salary 137 "50000", modify
    label def m_salary 144 "5500", modify
    label def m_salary 147 "5800", modify
    label def m_salary 150 "6000", modify
    label def m_salary 160 "700", modify
    label def m_salary 172 "800", modify
    label def m_salary 205 "Prefer not to answer", modify
    label def m_salary 214 "prefer not to say", modify
    label values currency currency
    label def currency 2 "Danish krone", modify
    label def currency 3 "Euro", modify
    label def currency 4 "GBP", modify
    label def currency 6 "Other – please specify:", modify

  • #2
    You cannot without an exchange rate. Knowing that X has a monthly income of 1000 units of one currency and Y has a monthly income of 5000 units of some other currency does not tell me anything about how the incomes of X and Y are related.

    Comment


    • #3
      You have a more pressing problem than converting m_salary to GBP..

      You have apparently used encode to create your numeric m_salary variable from a string variable, which I will pretend was named sm_salary in what I write below.

      The encode command is designed for assigning numerical codes to non-numeric strings like "Danish krone", "Euro", "GBP". The output of help encode instructs us

      Do not use encode if varname contains numbers that merely happen to be stored as strings; instead, use generate newvar = real(varname) or destring; see real() or [D] destring.
      You apparently did this because the original data contained values like "Prefer not to answer". You need to address these issues and then use destring. You should return to your original datea and run
      Code:
      tab sm_salary if missing(real(sm_salary))
      This will tell you how extensive the problem is with random textual answers. If you are content with all these textual values become Stata numeric missing values then you can do
      Code:
      destring sm_salary, generate(m_salary) force
      ]Otherwise you can read the output of help destring and decide what you need to do.

      Once you get m_salary correctly created, to convert currencies, you need to find appropriate conversion rates for the time(s) at which the data was gathered. Note that conversion rates change over time, so if your data includes survey results from multiple waves, you'll want several conversion rates, and your data will need a time variable indicating what time period the data represents.

      Perhaps someone else can advise further.

      Comment


      • #4
        Thank you Andrew and William.

        William - I did in fact use encode for the variable, thank you for pointing out my mistake. I have now corrected it in the data and a few other variables where I'd mistakenly used encode instead of destring.

        Comment

        Working...
        X