Announcement

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

  • #31
    Joseph Coveney that's a great point. You can really see the C/C++ influences in Stata's language design in your description. In fact, much like Stata, C doesn't have a boolean type. C does have a few exceptions to the rule that:
    0 is False. Everything else (everything else) is True.
    Some nonzero values (e.g. the null pointer) are treated as false in C, but all in all, very similar.

    You might not like that, but at least it's easy to know where things stand, and that's an important consideration in control flow.
    I felt like it was easier to know where things stand in a ternary logic system like in R. It is surprisingly intuitive and It leads to some very elegant code. It just felt natural. There were a lot of things about R that I did not like: (<- for assignment? seriously? I have to hit three keys now?), but the ternary logic is one place where R really shines. Then I started to learn ado, and wow is the syntax intuitive and easy to understand quickly. On the other hand, I was disappointed when I learned that the syntax leads to some regrettable beginner errors regarding missing numbers, whereas R seemed to handle all of these problems behind the scenes.

    I admit, it is possible I just prefer what is familiar to me, but I do think R does this particular thing better, and its because of the ternary logic system.

    Code:
    > d <- 1:10
    > d[3] = NA
    > d > 5
    [1] FALSE FALSE    NA FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
    Last edited by Daniel Schaefer; 07 Jul 2022, 22:20.

    Comment


    • #32
      Originally posted by Daniel Schaefer View Post
      Joseph Coveney that's a great point. You can really see the C/C++ influences in Stata's language design in your description. In fact, much like Stata, C doesn't have a boolean type. C does have a few exceptions to the rule that: Some nonzero values (e.g. the null pointer) are treated as false in C, but all in all, very similar.
      Same in Stata (Mata):

      Code:
      . mata :
      ------------------------------------------------- mata (type end to exit) -------------------------------------------------------------------------------------------------------------------------
      : printf(0 ? "true" : "false")
      false
      : printf(1 ? "true" : "false")
      true
      : printf(42 ? "true" : "false")
      true
      : printf(. ? "true" : "false")
      true
      : printf(.a ? "true" : "false")
      true
      : printf(NULL ? "true" : "false")
      false
      : end
      Last edited by daniel klein; 07 Jul 2022, 23:03. Reason: extended example

      Comment


      • #33
        While it is true that Stata users quickly become accustomed to the way missing values are managed in Stata, I believe that there still is slippery terrain that not every user is aware of. In this respect I recommend to read the "discussion" section in the help to -validly- (available at SSC). As an appetizer here a copy from this section:
        Code:
            The table below shows how Stata's raw generate interprets logical operators: !p (variable np), p&q
            (variable paq), p|q (variable pvq); and an exemplar equality relation p>=q (variable pgeq) -- for the nine
            possible combinations of values of indicator variables p, q.
        
            For example: for Stata, if both p and q are unknown (row nine), 'p and q' is nevertheless deemed to be
            true.  Asserting combined unknowns to be true is the stuff of fantasy novels, not data analysis.  The
            other red values in the table list other Stata errors.  (Notice, for example, that for Stata, where p is
            an indicator variable, !!p is not the same as p.)
        
            In contrast, the variables Np, pAq, pVq and pGEq have been constructed using validly generate. As can be
            seen, they preserve the correct formal (and intuitive) behaviour of logical and relational operators in
            the presence of missing values.
        
                          !p         p&q         p|q         p>=q        
             +--------------------------------------------------------+
             | p   q  | np   Np   paq   pAq   pvq   pVq   pgeq   pGEq |
             |--------+-----------------------------------------------|
          1. | 1   1  |  0    0     1     1     1     1      1      1 |
          2. | 1   0  |  0    0     0     0     1     1      1      1 |
          3. | 1   .  |  0    0     1     .     1     1      0      . |
             |--------+-----------------------------------------------|
          4. | 0   1  |  1    1     0     0     1     1      0      0 |
          5. | 0   0  |  1    1     0     0     0     0      1      1 |
          6. | 0   .  |  1    1     0     0     1     .      0      . |
             |--------+-----------------------------------------------|
          7. | .   1  |  0    .     1     .     1     1      1      . |
          8. | .   0  |  0    .     0     0     1     .      1      . |
          9. | .   .  |  0    .     1     .     1     .      1      . |
             +--------------------------------------------------------+
                       [Variables with uppercase code valid operators,
                        lowercase are plain Stata]
        Last edited by Dirk Enzmann; 10 Jul 2022, 08:17.

        Comment

        Working...
        X