Announcement

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

  • Manipulating strings

    Hi
    I am trying to convert my strings to lower case or uppercase.
    I used the command: strlower (variable_name), but this returned a r(199) - command not recognized error.
    I also received similar error when I tried strupper (variable_name).

    please kindly assist thanks

  • #2
    Without seeing you actual data or code, it is hard to troubleshoot. I am not a moderator but folks usually share their data via -dataex- and post their actual code as they seek help. See example below for the auto dataset (no spaces between strlower and (make).

    Code:
    sysuse auto, clear
    
    gen wanted = strlower(make)
    gen wanted2 = strupper(make)
    make wanted wanted2
    "AMC Concord" "amc concord" "AMC CONCORD"
    "AMC Pacer" "amc pacer" "AMC PACER"
    "AMC Spirit" "amc spirit" "AMC SPIRIT"
    "Buick Century" "buick century" "BUICK CENTURY"

    Comment


    • #3
      strlower() and strupper() are functions, not commands. In Stata a function can only be used inside an appropriate command. If foo is the name of a string variable then
      Code:
      replace foo = strlower(foo)
      is more likely to be what you want.
      Last edited by Nick Cox; 20 Jun 2023, 06:11.

      Comment


      • #4
        Thank you Nick and Girish, the solutions you gave worked perfectly!!

        Comment

        Working...
        X