Announcement

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

  • Replace missing values by group and with strings

    Dear users,

    I would like to replace all the string values by the last one of each group. For instance, in group 1 I want all the addresses to be "LAS PETUNIAS CON LOS GLADIOLOS"; in group 3 "CARLOS BOETHER 45" and so on.


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    
    input float group str82 address long type
     1 "LAS PETUNIAS CON LOS GLADIOLOS"  2
     1 "LOS GLADIOLOS 271"               2
     1 "LAS PETUNIAS CON LOS GLAD "      2
     1 "LAS PETUNIAS CON LOS GLAD "      2
     1 "LAS PETUNIAS" 2
     1 "LAS PETUNIAS " 2
     1 "LAS PETUNIAS " 2
     1 "LAS PETUNIAS CON LOS GLADIOLOS " 2
     1 "LAS PETUNIAS CON LOS GLADIOLOS " 2
     2 "CENTENARIO 2784"                 2
     2 "CENTENARIO 2784"                 2
     2 "CENTENARIO 2784"                 2
     3 "RICARDO BOETCHE "                2
     3 "CALLE CESAR MANZA 175"           2
     3 "CARLOS BOETHER "                 2
     3 "CARLOS BOETHER "                 2
     3 "CARLOS BOETHER 45 "                 2
     4 "6 RTE 1148"                      2
     4 "6 RTE 1148"                      2
     4 "6 RTE 1148"                      2
     5 "MANUEL RODRIGUEZ RO"             2
     5 "MANUEL RODRIGUEZ RO"             2
     5 "MANUEL RODRIGUEZ RO"             2
     5 "MANUEL RODRIGUEZ RO"             2
     5 "MANUEL RODRIGUEZ RO"             2
     5 "MANUEL RODRIGUEZ 440"            2
     5 "MANUEL RODRIGUEZ 440"            2
     5 "MANUEL RODRIGUEZ 440"            2
     5 "MANUEL RODRIGUEZ 440"            2
     5 "MANUEL RODRIGUEZ 440"            2
     5 "MANUEL RODRIGUEZ 140"            2
     5 "MANUEL RODRIGUEZ 140"            2
     5 "MANUEL RODRIGUEZ 140"            2
    
    end
    label values type type2
    label def type2 2 "SALA CUNA Y PARVULOS", modify
    I really don't have a clue on how to make this, I have been trying some combinations but since they are string values, it doesn't work.

    Daniel.

  • #2
    Code:
    bysort group: gen wanted = address[_N]

    Comment


    • #3
      Originally posted by Øyvind Snilsberg View Post
      Code:
      bysort group: gen wanted = address[_N]
      That's what I tried first but due to a typo it didn't work, now I realize.

      Thanks Mr. Snilsberg!

      Comment

      Working...
      X