Announcement

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

  • Renaming with renumbering

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte v1 str19 state float(v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24)
     0 "Rio Grande do Norte"  9.57 11.44 10.48 14.02 11.77 13.52 14.95  19.1 22.98  25.5 25.57 32.95 34.82 42.89    47 44.88 53.35 62.8 52.5 40.7   38 32.4
     1 "Acre"                19.56 21.07 25.73 24.48 18.56 18.51 23.01 19.48 19.56 22.14 22.49 21.97 27.41 30.14 29.36 27.01 44.45 62.2 47.1 33.6 32.9 21.2
     2 "Ceará"              17.19 17.01 18.88 20.15 20.12 20.98 21.81 23.19 23.89 25.33  31.8 32.73 44.63 50.95 52.31 46.75 40.63 60.2   54 26.2 45.2   37
     3 "Pernambuco"          56.17 58.81 54.37 55.34 50.66 51.46  52.6 53.04  50.9 44.98 39.48 39.15 37.25 33.92 36.19 41.16 47.26 57.2 44.1 36.3 38.3 34.8
     4 "Sergipe"             23.55  28.5 30.12 25.02 23.86 24.75 29.24 25.67 27.76 32.33 32.69 34.98 41.64 43.95 49.42 58.09 64.66 57.4 49.7 42.1 42.6 33.9
     5 "Alagoas"             26.55 29.06 34.32 35.61 35.11 39.89  53.1 59.51 60.33 59.35 66.88 71.39 64.63 65.07 62.78 52.33 54.18 53.7 43.4 34.2 37.3 31.8
     6 "Pará"               13.42 15.23 18.47 21.37 22.69 27.63 29.15 30.27 39.06 40.22 46.44 39.97 41.37 42.72 42.68 44.95 50.85 54.7 53.2 40.5 32.5 32.8
     7 "Bahia"                9.46 12.27  13.2 16.12 16.69 20.85 23.73 25.98 33.23 37.11 41.69 39.36 43.37 37.85 40.01 39.54 46.94 48.8 45.8 39.2 44.9 44.9
     8 "Amapá"                 34 36.49 35.04 34.59  31.1 32.96 32.81 27.02 34.25 30.32 38.83 30.54 36.22 30.61 34.09 38.22  48.7   48 51.4 49.1 41.7 53.8
     9 "Roraima"             47.59 32.02 35.17 29.67 23.12 24.28 27.52 27.93 25.44    28 26.86 20.64 30.67 43.85 31.79 40.15 39.67 47.5 71.8   35 29.2 35.5
    10 "Goiás"               21.9 22.81 26.29 25.37 28.21 26.12 26.33 26.04 30.66 32.09 32.96 37.36 45.38 46.24 44.26 45.34 45.34 42.8 38.6 32.6 30.5 26.1
    11 "Amazonas"             20.9 16.72 17.32 18.41 16.97 18.53 21.11  21.1 24.84 26.99 31.06 36.51 37.43 31.28 32.01 37.38 36.28 41.2 37.8 27.8 26.5 39.1
    12 "Rio de Janeiro"      52.75 50.57 56.61 54.54 51.43 48.16 47.48 41.62 35.67 33.51 35.44 29.67  29.4 31.22 34.74 30.62 36.38 38.4 37.6 34.6 28.3 27.2
    13 "Espírito Santo"     48.14 46.02 51.35 50.12 49.08    47 50.86 53.33 56.38 56.92 50.98 47.14 46.59 42.25 41.42  36.9 31.96 37.9 29.3 26.2 29.7 28.2
    14 "Tocantins"           15.15 17.89 14.08 16.58  15.8 14.55 17.19 16.63 18.51 22.37 23.64 25.77 26.73 23.61 25.45  33.2 37.64 35.9 36.7 24.2 28.5 24.3
    15 "Paraíba"            14.92 13.95 17.37 17.51 19.06 20.72 22.77 23.67 27.49  33.5 38.63 42.57 39.97 39.62 39.33 38.32 33.88 33.3 31.1 23.4 28.9 28.6
    16 "Mato Grosso"         40.92    38  36.4 34.25 31.62 32.36 31.36 30.55 31.68 33.31 32.03  32.8 34.47 36.39 42.12 36.84  35.7 32.9 28.7   26 28.1 24.9
    18 "Maranhão"            6.42  9.82 10.44 13.54 12.32 15.32 15.67 17.99 20.25 21.96  23.1 23.94 26.47 31.84 35.94 35.31 34.63 31.1 28.2 22.1 28.7 28.3
    19 "Rondônia"           35.37  40.7 42.95 38.88 38.04 36.17 37.44 27.17 32.14 35.77 34.95 28.55 33.08 27.95 33.06 33.93 39.33 30.7 27.1 25.9   23   25
    20 "Rio Grande do Sul"   16.55 17.98 18.37 18.15 18.67 18.64 18.09 19.85 21.92 20.54  19.5 19.35 22.12  20.8 24.31 26.17 28.57 29.3 23.8 16.8 17.6 15.9
    21 "Paraná"             18.85 21.17 23.13 25.79 28.22 29.01 29.82 29.54 32.53 34.61 34.33 32.11 32.98  26.7 26.89  26.3  27.4 24.4 21.5 19.4 21.6 20.8
    22 "Mato Grosso do Sul"  31.64 29.42 31.95 32.49 29.84 27.87 29.72 30.46 29.92 30.71 26.79 27.16 27.26 24.35 26.72 23.91 25.02 24.3 20.1 19.1 17.5 20.7
    23 "Minas Gerais"        12.06 13.05 16.32 20.85 22.84 21.95 21.44 20.92 19.59 18.68  18.6  21.6 22.98 22.91 22.78 21.72 22.01 20.4   16 13.4 12.6 11.4
    24 "Distrito Federal"    34.07 33.04 29.87 33.88 31.16 28.16 27.69 29.21 31.75 33.83 30.58 34.56 36.02    30 29.55 25.46 25.53 20.1 17.8   15 14.2 11.2
    25 "Piauí"               8.35  9.12 10.63 10.19 11.09 12.24 13.77 12.49 11.57 12.24 13.18 14.01 16.61 18.78 22.45 20.29 21.82 19.4   19 17.8 21.5 23.8
    26 "Santa Catarina"       8.38  8.75 10.58 11.95 11.22 10.79 11.18 10.45 13.25  13.4 13.17 12.84 12.86 11.89 13.45 14.03 14.24 15.2 11.9 11.4 11.2 10.1
    27 "São Paulo"          42.89 41.92 38.05 36.29 28.89 21.93  20.4 15.45 15.44 15.84 14.64 14.05 15.67 13.82 14.05 12.22 10.88 10.3  8.2  8.9    9  7.9
    end
    I wanna rename variables v3-v24 taxa2000, taxa2001....

    I've tried the following, and Stata tells me this
    Code:
    rename (v3-v24) *taxa(####), renumber(2000)
    too many wildcards in newname
        You requested v3-v24 be renamed *hom(####).  There are more wildcards in new than in old.  Wildcards in old and
        new correspond one-to-one from left-to-right unless you specify explicit subscripts in new.  Anyway, rename ran
        out of wildcards in old when matching the wildcards in new.  Perhaps you just made a mistake or perhaps you
        forgot an explicit subscript in new.  Or perhaps you forgot to specify option addnumber, which allows you to
        specify an extra #, (#), (##), ...
    r(198);
    I'll be honest (and maybe this is stupid of me to admit): I'd usually loop this problem and call it a day. But, I wanna learn how to do this since I've never learned it before. How might I go about solving this? Rule 16.2 seems relevant here...

  • #2
    I'm not sure there is a way to do this specifying a variable list for the old name.
    If you wanted to rename all the variables of the form v# you could do this
    Code:
    rename v# taxa(####), renumber(2000)
    That's a problem in your example because you don't want to include v1.
    Presuming your actual data is relatively simple like your example you could just rename v1 first and then use the wildcard syntax to catch v3-v24. However, if your real data then has another bank of v# variables you want to rename that won't work, in which case looping might end up being your easiest solution. (Unless I'm wrong about not being able to do it with a specific variable list, in which case hopefully someone will correct me).

    Comment


    • #3
      Code:
      rename (v3-v24) taxa#, addnumber(2000)

      Comment


      • #4
        My dataset is stolen from this Wikipedia page Sarah Edgington, by way of Stata's Python integration https://en.wikipedia.org/wiki/List_o...000s_and_2020s

        but yes this worked. Thanks so much! William Lisowski

        Comment

        Working...
        X