Announcement

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

  • variable transformation

    Please help me.
    I have data from 97 countries, and for each country, I have variables gdpcap1980, gdpcap1981, to gdpcap2022. I want to transform all of the data to logarithmic. Instead of using ln_gdpcapyyyy=ln(gdpcapyyyy) for each year manually, is there any more convenient way?

  • #2
    Originally posted by AHMAD THOIFUR View Post
    is there any more convenient way?
    Yes. Having the dataset in long format.

    Code:
    reshape long gdpcap, i(country) j(year)
    gen ln_gdpcap= ln(gdpcap)

    Comment


    • #3
      depending on your data setup, the following may do everything you want but (a) I don't know as you did not give us all the relevant information and (b) the following is untested as there is no data example (please read the FAQ and follow its advice):
      Code:
      forval i=1980/2022 {
      gen ln_gdpcap`i' = ln(gdpcap`i')
      also, please se
      Code:
      h forval
      h foreach
      edit: crossed with #2 which also makes assumptions about your data setup

      Comment

      Working...
      X