Announcement

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

  • Local expression? Trying to understand user-defined abar-command

    I'm trying to understand the user-written abar-command which defines the panel test for serial correlation introduced by Arellano & Bond 1991 (going through Stata files is sometimes easier than trying to understand the initial paper). At multiple occasions, they use the following syntax

    Code:
    tempvar wtvar e0
    gen double `wtvar'`=cond("`e(cmd)'"=="newey", "=","")'`e(wexp)' if `touse'
    ...
     `=cond("`id'" == "", "", "by `id' :")' egen double `ewi' = sum(`ewvar')
    What has me puzzled is that the expression after gen double `wtvar' is a local (`=cond("`e(cmd)'"=="newey", "=","")'), but the local is not defined anywhere and it also seems a very strange name for a local?

    I'm guessing it's some sort of ad-hoc conditional statement evaluation? But even then, if the condition it's false, the line reduces to gen double `wtvar' `e(wexp)' if `touse', which makes no sense to me? Is this perhaps some old Stata syntax? The program runs under version 7.0.

    I've attached the complete ado file if that helps.
    Attached Files

  • #2
    The syntax

    Code:
    `= exp'
    doesn't define a named local macro. It means

    1. carry out the calculation defined by the expression exp

    2. substitute the result here.

    Here are two examples:


    Code:
    . di "`=2 + 2'"
    4
    
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . su mpg
    
        Variable |        Obs        Mean    Std. Dev.       Min        Max
    -------------+---------------------------------------------------------
             mpg |         74     21.2973    5.785503         12         41
    
    . di "coefficient of variation is `= r(sd)/r(mean)'" 
    coefficient of variation is .2716543385281728
    
    .
    Documented at help macro.

    The first example you cite could, I guess quickly, be rewritten this way:

    Code:
    if "`e(cmd)'" == "newey" gen double `wtvar' = `e(wexp)' if `touse'
    else gen double `wtvar' `e(wexp)' if `touse'
    and seems designed to work around some idiosyncratic feature of newey.

    In this case I think I prefer the latter form.


    Last edited by Nick Cox; 14 Jul 2016, 11:58.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      The syntax

      [...]
      Ah! Normal commands return e(wexp) as "= weightvar", perhaps the old version of newey returned e(wexp) as "weightvar" instead. Thanks!

      Comment

      Working...
      X