Announcement

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

  • "Rename" isn't letting me change variable names to lowercase.

    I’ve concatenated four years of survey data (2013-2016). Most of the variables in each year are the same, but the use of capitalization in the variable names differs in a way that causes problems.

    For example, if I do a tabulation of “land_use”, I get results for survey years 2013-2015, but nothing for 2016. The problem is that the variable is named “LAND_USE” in the 2016 data. So if I do a tabulation of “LAND_USE”, I get results for 2016, but nothing for the 2013-2015 data years.

    I was hoping that the “rename” command with the “lower” option would be a quick and easy way to put everything in lower case, but here’s the error message I got:
    rename _all, lower

    563 new names specified repeatedly in newnames
    For instance, you requested the name age5p_african_acs_10_14 be assigned to 2 existing variables: age5p_african_acs_10_14
    and Age5p_African_ACS_10_14.
    r(198);
    Stata isn’t letting me rename “LAND_USE” to “land_use” because a variable called “land_use” already exists. Silly me, I thought the “force” option would help but the error message is the same:
    rename _all, lower force
    563 new names specified repeatedly in newnames
    For instance, you requested the name age5p_african_acs_10_14 be assigned to 2 existing variables: age5p_african_acs_10_14
    and Age5p_African_ACS_10_14.
    If anyone has a suggestion, I’d be grateful.

  • #2
    Stata is telling the truth. Rename variables to lower case, in this specific case, would produce some variables with the same name.
    Best regards,

    Marcos

    Comment


    • #3
      And a solution to your issue, assuming I read ti correctly that you have the 4 individual yearly datasets, to
      1. rename the variables to something consistent across all 4 datasets, for example with the rename code youre now using for the combined dataset
      2. Append the 4 datasets
      You probably want a variable 'year', which you might also need to create in each of the 4 datasets

      Comment


      • #4
        Jorrit's idea sounds best to me. I'd rather have the datasets as clean and consistent as possible before I did the merge.

        Perhaps you could also do something like

        replace land_use = LAND_USE if year == 2016

        Also, a force option seems very dangerous to me. What would Stata do with the existing variables by those names? Delete them? That might be ok for your specific situation but it could be disastrous in others.
        -------------------------------------------
        Richard Williams, Notre Dame Dept of Sociology
        StataNow Version: 19.5 MP (2 processor)

        EMAIL: [email protected]
        WWW: https://www3.nd.edu/~rwilliam

        Comment

        Working...
        X