Announcement

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

  • Importing from Excel to Stata as panel data.

    Hi, I am newbie in STATA and right now I have data as in the attached picture. I want to import it to STATA as panel variant (second attachment). Can you please help?
    Attached Files

  • #2
    Something like this:
    Code:
    import excel using spreadsheet_in_first_screenshot.xlsx, firstrow case(lower) clear
    ds country code, not
    local years `r(varlist)'
    local n_years: word count `years'
    forvalues i = 1/`n_years {
        rename `:word `i' of `years'' y`=2001+`i''
    }
    reshape long y, i(country) j(year)
    This will produce a data set resembling your second screenshot. But the spreadsheet does not appear to have two separate series of data corresponding to KOF and CCI, just one, and you don't say what it is or what you would like to call it. In the data set that results from the code above, it will just be called y. You can rename it once you have run the code.

    Note: The code assumes that everything on the unshown right-side of the spreadsheet is a continuation of the series that can be seen, and, in particular that everything in row 1 following column R continues the series of consecutive years.

    The code is untested and may contain typos or other errors, but, hopefully it gets you going in the right direction.

    Comment

    Working...
    X