Announcement

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

  • Rename rule

    Hello. I have a .dta file with column names A, B, C, etc. How can I rename the columns with the string value of the first row? Gracias

  • #2
    Code:
    foreach v of varlist _all {
        rename `v' `=`v'[1]'
    }
    drop in 1
    Note: This assumes that the string values in the first row are all legal Stata variable names. That means, in particular, they cannot contain any internal blank spaces, nor any characters other than digits, letters, and underscore (_) characters. Also, the first character cannot be a digit. And the length cannot exceed 32 characters. If these conditions are not all met, you must first clean the values in that first row.

    Here's a suggestion. Given that the column names are A, B, C, etc., I imagine that this file was imported from a spreadsheet. It looks like that -import- was done suboptimally. Try reimporting the data with -import excel- and don't forget to specify the -firstrow- option to that command. If you are not familiar with -import excel-, read its help file. It's a simple command to use and one of Stata's most useful.

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X