Announcement

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

  • opposite of strpos HELP URGENT PLEASE

    Hello,

    How to express the oppsite of strpos?
    How to express if variable does not belong in list?
    For exemple,


    gen index = "."
    local levels A B C D
    foreach level of local levels{
    capture confirm var `level'
    if _rc != 0 {
    replace index = "1" if strpos(var1,"`level'")


    }
    }

  • #2
    First, I don't understand why you are creating index as a string variable. Boolean expressions are best handled as numeric variables in Stata. Moreover, they are best coded as 0/1, not ./1. See http://www.stata.com/support/faqs/da...rue-and-false/ for more on how logical (Boolean) expressions work in Stata.

    As for the "opposite" of a Boolean expression, that is what the ! operator does. So if you want to evaluate an expression that is 1 when "`level'" is not found in var1, and 0 when it is, that expression would be -!strpos(var1, "`level'")-.

    Finally, do read the FAQ. Shouting HELP URGENT PLEASE is strongly discouraged in this forum.

    Comment


    • #3
      My probleme : i have a variable , i would like to complet it for modalities from list For exemple :
      var1
      A
      B
      .
      .
      i would like to complet the missing value from list
      var1 can also :
      var 1
      A
      .
      .
      .
      They are many combinaison!!
      i would like the oppsoite : i mean how can i say the oppsite of strpos(var1,"`level'")

      Comment


      • #4
        I'm sorry, but I don't understand this at all. Show a full example of data (use -dataex- for this purpose) that you would like to complete, and then show what you would like the end result to look like. And provide an explanation of why the end result should look like what you show, and not some other configuration.

        Again, the opposite of anything in Stata is !anything, though, at this point, it isn't clear to me what that has to do with your question.

        Comment


        • #5
          thznk you
          Im sorry for my english..
          !strpos isn't ok!!

          Comment


          • #6
            Is this a reposting of the problem posted earlier as

            compare contents two variable

            Comment


            • #7
              Originally posted by William Lisowski View Post
              Is this a reposting of the problem posted earlier as

              compare contents two variable
              yes beceause i cant modify my post to explaine my problem i have pb of expression in english

              Comment


              • #8
                Clyde gives good advice. Instead of trying to explain your problem in English,
                • in Stata, create a subset of your data to serve as an example
                • in Stata, using Stata's Data Editor, add a new variable and type in the values that you want the result to be
                • in Stata, install and use the dataex command to display your complete example
                • In Stata, copy the output of dataex from your Results window
                • in a new post on this topic, paste the dataex output.
                To install dataex, type ssc install dataex and when that is complete type help dataex to read the simple instructions for using it. Using dataex will enable those who want to help you to quickly and easily create a 100% faithful replica of your situation to test their ideas and code on.

                Comment

                Working...
                X