Announcement

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

  • replacing variable values with strmatch and self-named values which aren't in the dataset yet.

    Code:
    gen University=.
    replace University==Harvard University if strmatch(Degree,"*Harvard*")
    Harvard not found
    r(111);

    Code:
    gen University=.
    replace University==testHarvard University if strmatch(Degree,"*Harvard*")
    testHarvard not found
    r(111);

    I manually want to replace the . of the variable University by specific university names because now I have a variable called Degree containing string values like Harvardgraduated, Harvard school, Harvard college instead of 1 specific university name.

    Is there a solution for this? I couldn't find it

  • #2
    Hi,may be you can do as follow
    Code:
    gen str20 University= ""
    replace University = "testHarvard University" if strmatch(Degree,"*Harvard*")
    Bests,
    wanhaiyou

    Comment


    • #3
      Code:
      Code:
        
       gen University=.
      replace University=Harvard University if strmatch(Degree,"*Harvard*")
      Harvard not found
      r(111);



      (In my first post the replace code contained == instead of =) (That was a typo, the error is based on = instead of ==)


      Thanks for trying to help me but I still get the same error with your code. Could you tell me another suggestion please?

      Harvard University is a selfmade name, it's not the name of a variable, maybe that wasn't clear

      I have a variable called Degree containing string values like Harvardgraduated, Harvard school, Harvard college



      I want to rename those different kind of names with 1 universal name that describes them. Based on : http://satscores.us/
      The website contains a list of all the US universities like Harvard University, Yale University
      It's okay if I need to make 150 commands, 1 command for each university
      My dataset contains 753,594 observations, so I cannot do this without a good command to replace my different university names for universal names

      If i'm able to do so, I can link/merge the listed corresponding SAT scores of those universities with my dataset
      Last edited by Claire Thompson; 22 Nov 2014, 01:51.

      Comment


      • #4
        University is a string variable, so its values must be shown in quotes, and both following commands are illegal:
        Code:
        gen University=.
        replace University=Harvard University if strmatch(Degree,"*Harvard*")
        That is what the suggestion by wanhaiyou (who should register with his/her real first and last name) is about.

        You need to read about data types
        Code:
        help data types

        Comment

        Working...
        X