Announcement

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

  • Making the first row become Variable Names and Transposing the data

    Hello,

    How can I make the first row of observations become the Variable name?

    I would also like to have the data in a panel format (altough it's only for one country), therefore, how could I transpose this to a panel?

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input str52 A str12 B str37 C str14 D str18 E str17(F BJ)
    "Country Name" "Country Code" "Indicator Name"                        "Indicator Code" "1960"             "1961"             "2017"            
    "Italy"        "ITA"          "Inflation, consumer prices (annual %)" "FP.CPI.TOTL.ZG" "2.35016141377048" "2.05069731278691" "1.22653316645808"
    end

  • #2
    I'd guess that you obtained this data with -import excel- or -import delimited-, in which case you should import again but use the -firstrow- or -varnames()- option. If for some reason that does not work, you can do this:
    Code:
    foreach v of varlist * {
       local vname = strtoname(`v'[1])
       rename `v' `vname'
    }
    drop in 1
    destring _*, replace
    As for your desire for a panel format, -reshape long- is relevant. For your example (thanks for using -dataex-), I'm presuming you want:
    Code:
    reshape long _ , i(Country_Code) j(year)
    rename _ inflation

    Comment

    Working...
    X