Announcement

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

  • Question about anymatch

    I want to create a new variable which includes two types of degrees: bachelor and master.
    Also, each type of degree has three different schools: hesge, hesso, other hes

    My goal is to create a variable that includes bachelor and master degrees.
    Then I would like to categorise each bachelor and master in the same school.
    My code was as follows, but it doesn't seem to work the way I want. I began with anymatch, but maybe not suited for that:

    Code:
    egen byte diplome_hes = anymatch(bachelor_hes master_hes), values(2 3 4) //HES-GE, HES-SO & Other HES diplomas
    Then, I want to basically put in the same variable the value "2" for diplomas obtained at hes-so, regardless of whether these are masters or bachelors.
    Finally, the value "3" for diplomas obtained at other hes, regardless of whether these are masters or bachelors.

    Michael

  • #2
    anymatch() is no use here as it returns 1 and 0.

    This may help.

    Code:
    gen wanted = cond(inlist(2, bachelor, master), 2, cond(inlist(3, bachelor, master), 3, .))
    or

    Code:
    gen wanted = . 
    replace wanted = 2 if inlist(2, bachelor, master) 
    replace wanted = 3 if inlist(3, bachelor, master)
    Note that a numeric variable can't be both 2 and 3 in the same observation.

    Comment


    • #3
      This is exactly what I need!

      Thanks again.

      Comment

      Working...
      X