Announcement

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

  • rename doesn't read oldnames

    I have used this command successfully:
    rename (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP) ///
    (state govcon1981 govcon1982 govcon1983 govcon1984 govcon1985 govcon1986 govcon1987 govcon1988 govcon1989 ///
    govcon1990 govcon1991 govcon1992 govcon1993 govcon1994 govcon1995 govcon1996 govcon1997 govcon1998 govcon1999 ///
    govcon2000 govcon2001 govcon2002 govcon2003 govcon2004 govcon2005 govcon2006 govcon2007 govcon2008 govcon2009 ///
    govcon2010 govcon2011 govcon2012 govcon2013 govcon2014 govcon2015 govcon2016 govcon2017 govcon2018 govcon2019 ///
    govcon2020 govcon2021)
    but a few lines later with a different data set
    rename (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP) ///
    (state govt&s1981 govt&s1982 govt&s1983 govt&s1984 govt&s1985 govt&s1986 govt&s1987 govt&s1988 govt&s1989 ///
    govt&s1990 govt&s1991 govt&s1992 govt&s1993 govt&s1994 govt&s1995 govt&s1996 govt&s1997 govt&s1998 govt&s1999 ///
    govt&s2000 govt&s2001 govt&s2002 govt&s2003 govt&s2004 govt&s2005 govt&s2006 govt&s2007 govt&s2008 govt&s2009 ///
    govt&s2010 govt&s2011 govt&s2012 govt&s2013 govt&s2014 govt&s2015 govt&s2016 govt&s2017 govt&s2018 govt&s2019 ///
    govt&s2020 govt&s2021)
    Give me
    oldnames and newnames do not match
    You specified 1 pattern or name for oldname and 42 patterns or names for newnames.
    r(198);

    Probably a typo I'm not seeing? Or...?
    Thanks
    Tom

  • #2
    The error message is misleading. Because govt&s1981 and the like contain the & character that is not allowed in names, rename interprets these as "patterns". The thing is, & is not a valid wildcard character in rename either, so the error should point to an invalid name or pattern instead.

    By the way, if those data come from Excel, you can specify the variable names during import.

    Comment


    • #3
      Ahh--I'm rusty (been using Stata for a long time but haven't done this in a time). Much appreciated. For decades this has been a great community.
      Thanks so much.

      Comment


      • #4
        Not the question but another way to do it is

        Code:
        rename A state 
        
        rename (B-AP) (govcon#), addnumber(1981)

        Comment

        Working...
        X