Announcement

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

  • Misspellings

    Hi! I am trying to clean the variable "pais_limp", which has multiple misspelling. I am running the next code, which is not working

    replace pais_limp = "Venezuela" if pais_limp= "CARACAS", "CARACAS VENEZUELA", "CARACAS VENEZULA", "FRIAS VENEZUELA", "MARACAIBO VENEZUELA")
    replace pais_limp ="Venezuela", if pais_limp= "VANAZUELA", "VANEZUELA", "VEEZUELA", "VEMEZUELA", "VENENSUELA", "VENENZUELA", "VENESUELA", "VENEZOLANA", "VENEZOLANO")
    replace pais_limp ="Venezuela", if pais_limp= "VENEZOLANOS", "VENEZUELA", "VENEZUELA CARACAS", "VENEZUELA ISLA CARIBE", "VENEZUELA MARACAIBO", "VENEZUELA VARINAS", "VENEZUELQ")
    replace pais_limp ="Venezuela", if pais_limp= "VENEZUELW", "VENEZULA", "VENEZULA MARACAIBO", "VENRZUELA", "VEZUELA", "venezuela")


    Can anyone help me?

  • #2
    Your syntax is illegal in three ways. First, = is not the correct notation for the relationship of equality in Stata. = denotes that the thing on the right will fill or replace the thing on the left. The relationship that two things are equal is denoted with ==.

    Second, even with ==, you cannot put a list of alternatives on the right hand side. You can only put one thing. What you are looking for is taken care of by the -inlist()- function.

    Third, in all but the first of your commands, you have placed a comma (,) before -if-. But in Stata syntax, -if- qualifiers must precede the comma. The comma is used to set off options from the main command. -if- is not an option.

    Putting this all together:

    Code:
    replace pais_limp = "Venezuela" if inlist(pais_limp, "CARACAS", "CARACAS VENEZUELA", "CARACAS VENEZULA", "FRIAS VENEZUELA", "MARACAIBO VENEZUELA")
    replace pais_limp ="Venezuela" if inlist(pais_limp, "VANAZUELA", "VANEZUELA", "VEEZUELA", "VEMEZUELA", "VENENSUELA", "VENENZUELA", "VENESUELA", "VENEZOLANA", "VENEZOLANO")
    replace pais_limp ="Venezuela" if inlist(pais_limp, "VENEZOLANOS", "VENEZUELA", "VENEZUELA CARACAS", "VENEZUELA ISLA CARIBE", "VENEZUELA MARACAIBO", "VENEZUELA VARINAS", "VENEZUELQ")
    replace pais_limp ="Venezuela" if inlist(pais_limp, "VENEZUELW", "VENEZULA", "VENEZULA MARACAIBO", "VENRZUELA", "VEZUELA", "venezuela")

    Comment


    • #3
      see
      Code:
      h inlist
      as the code you show is not legal; when you are looking at the help file, note the restriction when a variable is a string variable

      note that you could fix your code by inserting the "or" character (|) if you prefer to do it that way (i.e., eliminate the commas, insert "|" and be sure to include the "pais_limp==" (note the double equals signs which are needed when doing a logic test)

      added in edit: crossed with #2

      Comment


      • #4
        Excellent!! Dear Clyde and Rich! t worked perfectly! Thank youu

        Comment

        Working...
        X