Announcement

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

  • compare contents two variable

    I was wondering if you know of any command in stata that can compare modalities of two columns(2 string variable.)
    iw would like to complete for exemple var1 withi different modalities of var2
    For example :

    var1 var2
    A C
    AB D
    D AE
    . AB

    HERE, i would like to comple the missing value of var1 with AE because AE is in var2 and not in var1
    i used lovelsof but they are problem!!
    levelsof var1, local(levels)
    levelsof var2, local(level)
    gen index = 1 if strpos(var2,"`levels'")
    Last edited by ANA KHAILFI; 15 Jan 2017, 06:25.

  • #2
    Ana:
    you may want to try:
    Code:
    . egen flag=diff( var1 var2 )///to check whether observations in -var1- and -var2- are equal or not. In this latter case -flag- will take on 1 (0 otherwise)
    
    . replace var1="AE" if var1==""///to replace missing values as desired
    (1 real change made)
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you Carlo
      But AE is an exemple
      This résult of collapse fonction
      So, il want replace missing value of var 1 with the other modalities of var2.

      Comment


      • #4
        Ana:
        try:
        Code:
        replace var1=var2 if var1==""
        Kind regards,
        Carlo
        (Stata 19.0)

        Comment


        • #5
          Thank you
          But Carlo il thank il must use levelsof. .
          If modalities of var 2 not in var 1
          Il add this modalities tout var 1

          Comment


          • #6
            Ana:
            sorry, but I cannot follow your query, then.
            Kind regards,
            Carlo
            (Stata 19.0)

            Comment


            • #7
              Thank you carlo

              Comment


              • #8
                This discussion is continued at

                opposite of strpos

                Comment

                Working...
                X