Announcement

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

  • Joke programs in Stata

    Although it's more obvious on social media than here, several joke commands in Stata (read that as: several light-hearted Stata programs) have been posted recently, and welcome they are too.

    This is more of a meta-post, on how to write joke programs, as if you glance at the code of these programs you will find not only a certain communality of style (meaning, programmers copy good or at least workable ideas from each other, and how else would we get anywhere), but also a certain long-windedness of code, rather like this not quite interminable sentence.

    Here are some very small tricks for writing joke programs, illustrated by example.

    Code:
    program myjoke 
    
    local myjoke1 "The lognormal is more normal than the normal"
    local myjoke2 "Statistics means never having to say that you are certain"
    local myjoke3 "The method of 'postulating' what we want has many advantages; they are the same as the advantages of theft over honest toil. (Bertrand Russell)"
    local myjoke4 "Sure, he invented fire. But what has he done since? (some caveperson academic)"
    local myjoke5 "Not even wrong (Wolfgang Pauli)"
    local myjoke6 "Notation is a branch of etiquette, not of logic"
    local myjoke7 "Be careful where you point that straight line. It could go off anywhere."
    local myjoke8 "Local means what it says"
    local myjoke9 "PCA isn't a washing machine. Muck stays in the wash. At best it ends up on low eigenvalue PCs." 
    local myjoke10 "Your punishment is that your code did exactly what you asked for"
    local myjoke11 "Reputation, like almost anything else, is measured with error"
    local myjoke12 "To see what is going on, you really need a graph"
    local myjoke13 "Intuitive means familiar, not intuitive"
    local myjoke14 "Theory is just somebody else's speculation that got into the literature" 
    local myjoke15 "Variance is the attitude of one statistician to another (R.A. Fisher, supposedly)" 
    local myjoke16 "Confidence intervals are really diffidence intervals" 
    local myjoke17 "A significance test is a roundabout way of finding out that you need a bigger sample" 
    local myjoke18 "Despite its purpose, no-one really wants to read a legend" 
    
    * 18 should be replaced by the maximum number of jokes if different 
    local which = runiformint(1, 18) 
    
    di "{p}`myjoke`which''{p_end}"
    
    end
    Notice how you don't need a multiple branching structure or to wire in certain random number results into the code. You just need to define your jokes and call up one with a single call to a function. Also, a structure like this is easy to extend. The SMCL tags in the display ensure that text is wrapped fairly within any narrow Results window.




  • #2
    Nick, I ran your code and it formatted my hard drive, please help

    Thanks for sharing!
    Best wishes

    (Stata 16.1 MP)

    Comment


    • #3
      In this spirit, I'll share with the community the date/horoscope program on which I've relied heavily in recent months, with the hope that you too will find it useful.
      Code:
      cap prog drop horoscope
      prog horoscope
       local w=dow((date(c(current_date),"DMY")))+1
       local r=runiformint(1,7)
       di ""
       di in red "Today's date is " c(current_date)
       di in red "It might be " word("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", `w')
       if `w' != `r' {
        di in red "But it might also be " word("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", `r')
       }
       if `w' == `r' {
        di in red "In fact it's probably " word("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", `r')
       }
       di in red "Your horoscope for today is " word("😀 😂 😎 😳 😩 😢 🤔",runiformint(1,7))
      end
      (P.S. I'm not sure the emojis in the penultimate line translate correctly on all operating systems.)

      Comment


      • #4
        Code:
        di in red
        isn't documented any more but still works -- and it should be easy to guess what it does.

        Code:
        di as err
        is the modern equivalent.

        Comment

        Working...
        X