Announcement

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

  • IF Command

    Dear Stata collegues
    I´m having some doubts with the if command.
    I need to run tests with the limitations below, but what I’m trying is not working:
    The limitations are:
    • w>0;
    • Classification==2;
    • retlag or epslag >0
    I tried to use this command to do so:
    • xtreg vcret epslag retlag vcsizelag vcpbooklag vcdesvlag vcturnlag, fe robust, if w>0 & retlag>0 | epslag>0 & Classificacao==2
    However, I observed that when I use it, the number of observations (785265) is much greater than the sum of the number of observation with only ret >0 (30878) and only epslag >0 (25589). The commands that I run to do these last ones were:
    • xtreg vcret retlag vcsizelag vcpbooklag vcdesvlag vcturnlag, fe robust, if w>0 & retlag>0 & Classificacao==2
    • xtreg vcret retlag vcsizelag vcpbooklag vcdesvlag vcturnlag, fe robust, if w>0 & epslag>0 & Classificacao==2
    Even more, I observed that when I change the order of the sequences, the results are different too. When I use the command below, I have 777611 observations.
    • xtreg vcret epslag retlag vcsizelag vcpbooklag vcdesvlag vcturnlag, fe robust, if w>0 & Classificacao==2 & retlag>0 | epslag>0
    I think that I have to join the limitation “retlag or epslag >0”, but I don´t know how to do this.

    Can someone help?

    Thanks.

  • #2
    Try
    Code:
    xtreg vcret epslag retlag vcsizelag vcpbooklag vcdesvlag vcturnlag, fe robust, if w>0 & (retlag>0 | epslag>0) & Classificacao==2
    The and operator & has a higher priority than the or operator | (like multiplication versus addition) so by default all the ands get calculated first, then the or is applied to the results. See the output of help operators for more details on order of evalution.

    It never hurts to use parentheses to make your requirements explicit.

    Comment


    • #3
      Hi William.

      It wasn´t clear how to make my requirements clear.

      Seems that it works.

      The number of observations now is 35514, closer to the sum of the others tests than before.

      Thanks.

      Comment

      Working...
      X