Announcement

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

  • import shorter variable names

    I recently imported an Excel file and there are several variable names that end in a year as such:

    longitudepublicschool2016 / latitudepublicschool2016

    I'm wondering if there is a way to import them without the last four digits? Or is there a renaming convention that identifies numbers and removes them from variable names?

    What I am doing afterwards is:
    Code:
    rename latitudepublicschool2016 latcod
    rename longitudepublicschool2016 loncod
    and I'm going to repeat this when new data comes out next year. Next year, they'll import as longitudepublicschool2017 and latitudepublicschool2017, so I would have to go into my .do file and change all mentions of 2016 into 2017 to conform to the new data It would be easier to just remove the year in the variable name to begin with.

  • #2
    There are (at least) two ways to do this with the -rename- function. See the output of -help rename- and the PDF documentation for it for some really interesting expressions.

    Supposing, based on your example, that your variables always end with the year, and you only wish to strip that portion away, you may do the following, writing one line per year.

    Code:
    rename (*2016) (*)
    rename (*2017) (*)
    This can be condensed to remove any trailing number as follows.

    Code:
    rename (*#) (*)

    Comment


    • #3
      Such an easy fix! Thanks

      Comment

      Working...
      X