Announcement

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

  • Converting currencies

    Hey, I have been looking for an answer but did not really find one and therefore hope to gain some knowledge here. I am working with a panel dataset including firms from all around the world. I need to convert two variables, a firm's total assets and a firm's r&d expenditure, into USD from various other currencies. In theory, I can just create a new variable by dividing e.g. the total assets by the exchange rate. This works only if the exchange rate is higher than one though. On the other hand I could multiply the value of total assets by the exchange rate if the exchange rate is lower than one. Basically, I am looking for a code that allows me to implement an if condition that divides total assets by the exchange rate IF it is higher than 1 and multiplies IF lower than 1.
    I am thinking about something like the following:

    gen assetsUSD = TA / FX if FX > 1 & TA * FX if FX < 1

    (TA = Total assets & FX = Exchange rate)

    I did not use the dataex yet as I thought it might be solvable without looking at the specific data.

    Highly appreciate any help!



  • #2
    Hi Ismael,

    What about this?

    Code:
    gen assetsUSD = .
    replace assetsUSD = TA / FX if FX > 1
    replace assetsUSD = TA * FX if FX <= 1

    Comment


    • #3
      I should also say that it is important to keep in mind that logical expressions like this are not totally safe if FX contains missing values. See here: https://www.stata.com/support/faqs/d...issing-values/

      It shouldn't matter in this case, because multiplying or dividing by missing should give you missing, but it is good practice to be explicit.

      Code:
      gen assetsUSD = .
      replace assetsUSD = TA / FX if FX > 1 & FX != .
      replace assetsUSD = TA * FX if FX <= 1

      Comment


      • #4
        In theory, I can just create a new variable by dividing e.g. the total assets by the exchange rate.
        Let's assume we want to convert total assets in EUR to total assets in USD.

        If the exchange rate is expressed as the number of EUR exchanged for 1 USD, then total assets in USD is total assets in EUR divided by the EUR-to-USD exchange rate.

        If the exchange rate is expressed as the number of USD exchanged for 1 EUR, then total assets in USD is total assets in EUR multiplied by the USD-to-EUR exchange rate.

        And this works because the EUR-to-USD exchange rate is 1 divided by the USD-to-EUR exchange rate.

        This works only if the exchange rate is higher than one though.
        This is incorrect.

        Comment

        Working...
        X