Announcement

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

  • Problems with command strlower

    Hello everybody,
    I have a big dataset in which different categories in the variable “occupations” are recorded with the first letter in capital letter. I would need to convert this letter in lower letter: uppercases to lowercases, necessary to merge later with another dataset with lowercases. But Stata doesn’t recognize the command "strlower” or even display strlower. I have looked into the manual and forums, and still I have this doubt to solve. Thank you in advance.
    strlower (Occupations), converted to lowercase
    command strlower is unrecognized
    r(199);
    display strlower
    strlower not found
    r(111);

  • #2
    That's because -strlower- is not a command. It's a function. What you want is:

    Code:
    gen occupation_lc = strlower(Occupations)
    (Or, you can just do -replace Occupations = strlower(Occupations)- if you are sure you will never need to use the mixed-case version again.)

    Comment


    • #3
      Thank you so much, the code works perfectly.

      Comment


      • #4
        Clyde's recommendation with regards to strlower() function is 100% correct. But I was alerted by the merging strategy intended by Maria. Merging based on the text key is a rather risky strategy, and converting everything to lower case is dealing only with one aspect of differences in spelling between the two datasets. Provided that this was generated by some code, and known to be the only difference in the code it is fine, but if you are dealing with human entries, then you will still end up with a lot of mismatches. Merging by codes is advisable, provided the codes exist, or could be generated from other variables present.

        For example, all of the lines below are different:
        Code:
        example
        exаmple
        eхample
        And if you do any pairwise comparison to verify this in Stata:
        Code:
        . display ("example"=="exаmple")
        0
        The problem has nothing to do with the case and is hard to spot, but may occur when you are dealing with human-entered (or even OCRed) text.

        Best, Sergiy

        Comment

        Working...
        X