Announcement

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

  • rpaxioms: new module on SSC for testing revealed preference axioms

    With thanks to Kit Baum, the module rpaxioms containing the three commands checkax, aei and powerps, is now available from SSC.

    Use
    Code:
    ssc install rpaxioms
    to install the module containing the three commands.

    checkax allows the user to test whether consumer demand data satisfy certain revealed preference axioms at a given efficiency level. The second command, aei, calculates measures of goodness-of-fit when the data violates the axioms. The third and final command, powerps, calculates the power against uniform random behaviour and predictive success for the axioms at any given efficiency level.

    For further information, please refer to Demetry, Hjertstrand and Polisson (2020) "Testing Axioms of Revealed Preference", IFN Working Paper Nr 1342 ; as well as the help files of respective commands.


    For illustration, we use made up price and quantity data; matrices P and X below.

    Code:
    clear
    input A B C D E F G H I J
    8 2 1 6 9   27 22 29 28 43
    4 4 5 6 5   44 33 38 27 37
    6 6 9 8 2   22 25 48 27 43
    6 5 7 1 5   32 20 48 24 40
    2 1 6 7 4   20 49 38 49 23
    6 3 9 6 5   26 33 30 49 35
    7 9 1 2 9   20 49 46 45 30
    5 1 10 10 5 25 43 33 42 22
    9 9 2 6 4   24 20 48 25 24
    8 1 6 5 4   28 41 21 31 26
    4 7 2 10 2  25 41 36 25 40
    5 6 6 7 3   24 39 42 20 33
    4 3 1 5 1   38 37 25 29 41
    8 6 8 9 5   47 26 30 41 27
    8 2 9 6 3   49 43 25 39 20    
    5 7 10 6 3  26 27 29 36 36
    7 6 10 7 5    34 31 32 33 28
    10 1 6 4 2    31 47 37 28 49    
    8 1 3 3 5    36 46 21 35 48
    8 2 2 6 8   28 32 37 43 32
    end
    
    mkmat A B C D E, matrix(P)
    mkmat F G H I J, matrix(X)

    The first command, checkax, works as follows: with the price and quantity matrices as inputs, the command checks whether the data satisfy the chosen axiom of revealed preference (in this case, no axiom was specified, and therefore eGARP was chosen per default) at the given efficiency level eff (also set to 1 per default if not otherwise specified).


    Code:
    . checkax, price(P) quantity(X)
    
    
    
    ---------------------------------------------------------------------------------
           Axiom | Pass        #vio        %vio       Goods         Obs         Eff
    -------------+-------------------------------------------------------------------
           eGARP |    0         136       35.79           5          20        1.00
    ---------------------------------------------------------------------------------
    .
    . return list
     
    scalars:
                   r(PASS) =  0
                r(NUM_VIO) =  136
               r(FRAC_VIO) =  35.79
                  r(GOODS) =  5
                    r(OBS) =  20
                    r(EFF) =  1
     
    macros:
                  r(AXIOM) : "eGARP"
    The code below illustrates checkax with non-default settings.

    Code:
    . checkax, price(P) quantity(X) axiom(eHARP) efficiency(0.95)
    
    
    
    ---------------------------------------------------------------------------------
           Axiom | Pass        #vio        %vio       Goods         Obs         Eff
    -------------+-------------------------------------------------------------------
           eHARP |    0          20      100.00           5          20        0.95
    ---------------------------------------------------------------------------------

    Similarly, aei uses the price and quantity matrices and shows at which efficiency level the data would pass the specified axiom.

    Code:
    . aei, price(P) quantity(X)
    
    ----------------------------------------------------------
           Axiom |       AEI        Tol      Goods        Obs
    -------------+--------------------------------------------
           eGARP |     .9056   1.00e-12          5         20
    ----------------------------------------------------------
    
    . return list
     
    scalars:
                    r(AEI) =  .9055851063826594
                    r(TOL) =  1.00000000000e-12
                  r(GOODS) =  5
                    r(OBS) =  20
     
    macros:
                  r(AXIOM) : "eGARP"
    And here is an example of aei with non-default settings:

    Code:
    . aei, price(P) quantity(X) axiom(eWGARP) tol(6)
    
    ----------------------------------------------------------
           Axiom |       AEI        Tol      Goods        Obs
    -------------+--------------------------------------------
          eWGARP |     .9056   1.00e-06          5         20
    ----------------------------------------------------------

    Lastly, here is an illustration of powerps with default settings...


    Code:
    . powerps, price(P) quantity(X)
    
    ------------------------------------------------------------------------------------------------------
          Axioms |     Power         PS       Pass        AEI        Sim        Eff      Goods        Obs
    -------------+----------------------------------------------------------------------------------------
           eGARP |      .995      -.005          0   .9055851       1000          1          5         20
    ------------------------------------------------------------------------------------------------------
     
    Summary statistics for simulations:
     
    ------------------------------------
           eGARP |      #vio       %vio
    -------------+----------------------
            Mean |    39.497   10.39415
       Std. Dev. |  25.68762   6.759885
             Min |         0          0
              Q1 |        18       4.74
          Median |        37       9.74
              Q3 |        59      15.53
             Max |       120      31.58
    ------------------------------------
    .
    . return list
     
    scalars:
            r(POWER_egarp) =  .995
               r(PS_egarp) =  -.005
             r(PASS_egarp) =  0
              r(AEI_egarp) =  .9055851063826594
              r(SIM_egarp) =  1000
              r(EFF_egarp) =  1
            r(GOODS_egarp) =  5
              r(OBS_egarp) =  20
     
    macros:
            r(AXIOM_egarp) : "eGARP"
     
    matrices:
         r(SUMSTATS_egarp) :  7 x 2
       r(SIMRESULTS_egarp) :  1000 x 2

    As opposed to the previous two commands, powerps can take several axioms in the axiom() option, as illustrated below:

    Code:
    . powerps, price(P) quantity(X) axiom(eWARP eSARP) sim(2000) aei progress
    Loop progress (2000)
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5
    ..................................................    50
    ..................................................   100
    ..................................................   150
    (output omitted)
    ..................................................  1950
    ..................................................  2000
    
    ------------------------------------------------------------------------------------------------------
          Axioms |     Power         PS       Pass        AEI        Sim        Eff      Goods        Obs
    -------------+----------------------------------------------------------------------------------------
           eWARP |     .9905     -.0095          0   .9055851       2000          1          5         20
           eSARP |      .994      -.006          0   .9055851       2000          1          5         20
    ------------------------------------------------------------------------------------------------------
     
    Summary statistics for simulations:
     
    -----------------------------------------------
           eWARP |      #vio       %vio        AEI
    -------------+---------------------------------
            Mean |    7.6935   4.049415   .8405483
       Std. Dev. |  4.513174   2.375057   .0855724
             Min |         0          0   .4537143
              Q1 |         4       2.11   .7889272
          Median |         7       3.68   .8519566
              Q3 |        10       5.26   .9036704
             Max |        31      16.32          1
    -----------------------------------------------
     
     
    -----------------------------------------------
           eSARP |      #vio       %vio        AEI
    -------------+---------------------------------
            Mean |    39.382   10.36381   .8358594
       Std. Dev. |  26.20529   6.896192   .0839901
             Min |         0          0   .4537143
              Q1 |        18       4.74   .7851447
          Median |        36       9.47   .8458362
              Q3 |        58      15.26    .897139
             Max |       123      32.37          1
    -----------------------------------------------

  • #2
    We have updated the commands on SSC. The following changes were made:
    • Corrected an error in the final tabulation of eGARP violations
    • Added eSGARP as an axiom to be tested
    • Allowed all three commands to take any number of axioms as an argument in axiom()
    • Sped up calculations in the powerps command
    • When return list has an item that is independent of the axioms being tested, we removed the suffix _axiom
    • Changed the table layouts

    Using the same made up price and quantity data as in the initial post, which created matrices P and X, below is an illustration of the commands in their revised state.

    Code:
    clear
    input A B C D E F G H I J
    8 2 1 6 9   27 22 29 28 43
    4 4 5 6 5   44 33 38 27 37
    6 6 9 8 2   22 25 48 27 43
    6 5 7 1 5   32 20 48 24 40
    2 1 6 7 4   20 49 38 49 23
    6 3 9 6 5   26 33 30 49 35
    7 9 1 2 9   20 49 46 45 30
    5 1 10 10 5 25 43 33 42 22
    9 9 2 6 4   24 20 48 25 24
    8 1 6 5 4   28 41 21 31 26
    4 7 2 10 2  25 41 36 25 40
    5 6 6 7 3   24 39 42 20 33
    4 3 1 5 1   38 37 25 29 41
    8 6 8 9 5   47 26 30 41 27
    8 2 9 6 3   49 43 25 39 20    
    5 7 10 6 3  26 27 29 36 36
    7 6 10 7 5    34 31 32 33 28
    10 1 6 4 2    31 47 37 28 49    
    8 1 3 3 5    36 46 21 35 48
    8 2 2 6 8   28 32 37 43 32
    end
    
    mkmat A B C D E, matrix(P)
    mkmat F G H I J, matrix(X)

    The first command, checkax, works as follows: with the price and quantity matrices as inputs, the command checks whether the data satisfy the chosen axiom of revealed preference (in this case, no axiom was specified, and therefore eGARP was chosen per default) at the given efficiency level eff (also set to 1 per default if not otherwise specified).


    Code:
    . checkax, price(P) quantity(X)
     
                  Number of obs           =      20 
                  Number of goods         =       5 
                  Efficiency level        =       1 
     
    -----------------------------------------------
           Axiom |      Pass       #vio       %vio 
    -------------+---------------------------------
           eGARP |         0        161      42.37 
    -----------------------------------------------
     
    . return list
     
    scalars:
         r(FRAC_VIO_eGARP) =  42.37
          r(NUM_VIO_eGARP) =  161
             r(PASS_eGARP) =  0
                    r(EFF) =  1
                  r(GOODS) =  5
                    r(OBS) =  20
     
    macros:
                  r(AXIOM) : " eGARP"
    The code below illustrates checkax with non-default settings.

    Code:
    . checkax, price(P) quantity(X) ax(eGARP eHARP) eff(0.95)
     
                  Number of obs           =      20 
                  Number of goods         =       5 
                  Efficiency level        =     .95 
     
    -----------------------------------------------
           Axiom |      Pass       #vio       %vio 
    -------------+---------------------------------
           eGARP |         0        104      27.37 
           eHARP |         0         20        100 
    -----------------------------------------------

    Similarly, aei uses the price and quantity matrices and shows at which efficiency level the data would pass the specified axiom.

    Code:
    . aei, price(P) quantity(X)
     
        Number of obs           =         20 
        Number of goods         =          5 
        Tolerance level         =    1.0e-12 
     
    -------------------------
           Axiom |       AEI 
    -------------+-----------
           eGARP |  .9055851 
    -------------------------
     
    . return list
     
    scalars:
                    r(TOL) =  1.00000000000e-12
                  r(GOODS) =  5
                    r(OBS) =  20
              r(AEI_eGARP) =  .9055851063826594
     
    macros:
                  r(AXIOM) : " eGARP"
    And here is an example of aei with non-default settings:

    Code:
    . aei, price(P) quantity(X) axiom(eWGARP eCM) tol(6)
     
        Number of obs           =         20 
        Number of goods         =          5 
        Tolerance level         =    1.0e-06 
     
    -------------------------
           Axiom |       AEI 
    -------------+-----------
          eWGARP |  .9055848 
             eCM |  .8473897 
    -------------------------

    Lastly, here is an illustration of powerps with default settings...


    Code:
    
    . powerps, price(P) quantity(X)
     
                           Number of obs           =        20 
                           Number of goods         =         5 
                           Simulations             =      1000 
                           Efficiency level        =         1 
     
    ----------------------------------------------------------
          Axioms |     Power         PS       Pass        AEI 
    -------------+--------------------------------------------
           eGARP |      .995      -.005          0   .9055851 
    ----------------------------------------------------------
     
    Summary statistics for simulations:
     
    ------------------------------------
           eGARP |      #vio       %vio 
    -------------+----------------------
            Mean |    47.339   12.45762 
       Std. Dev. |  29.45589   7.751351 
             Min |         0          0 
              Q1 |        24       6.32 
          Median |        45      11.84 
              Q3 |      68.5     18.025 
             Max |       143      37.63 
    ------------------------------------
     
    . return list
     
    scalars:
            r(POWER_eGARP) =  .995
               r(PS_eGARP) =  -.005
             r(PASS_eGARP) =  0
              r(AEI_eGARP) =  .9055851063826594
                    r(SIM) =  1000
                    r(EFF) =  1
                  r(GOODS) =  5
                    r(OBS) =  20
     
    macros:
                  r(AXIOM) : " eGARP"
     
    matrices:
         r(SUMSTATS_eGARP) :  7 x 2
       r(SIMRESULTS_eGARP) :  1000 x 2

    powerps, just as checkax and aei, can take several axioms in the axiom() option, as illustrated below:

    Code:
    . powerps, price(P) quantity(X) axiom(eWARP eSARP) aei sim(2000) tol(6) progress
    Loop progress (2000)
    ----+--- 1 ---+--- 2 ---+--- 3 ---+--- 4 ---+--- 5 
    ..................................................    50
    ..................................................   100
    ..................................................   150
    (output omitted)
    ..................................................  1950
    ..................................................  2000
    
    
    
                           Number of obs           =        20 
                           Number of goods         =         5 
                           Simulations             =      2000 
                           Efficiency level        =         1 
     
    ----------------------------------------------------------
          Axioms |     Power         PS       Pass        AEI 
    -------------+--------------------------------------------
           eWARP |     .9905     -.0095          0   .9055851 
           eSARP |      .994      -.006          0   .9055851 
    ----------------------------------------------------------
     
    Summary statistics for simulations:
     
    -----------------------------------------------
           eWARP |      #vio       %vio        AEI 
    -------------+---------------------------------
            Mean |    7.6935   4.049415   .8405483 
       Std. Dev. |  4.513174   2.375057   .0855724 
             Min |         0          0   .4537141 
              Q1 |         4       2.11   .7889271 
          Median |         7       3.68   .8519568 
              Q3 |        10       5.26   .9036708 
             Max |        31      16.32          1 
    -----------------------------------------------
     
    -----------------------------------------------
           eSARP |      #vio       %vio        AEI 
    -------------+---------------------------------
            Mean |   47.0755   12.38842   .8358594 
       Std. Dev. |  29.81487   7.845959   .0839901 
             Min |         0          0   .4537141 
              Q1 |        23       6.05   .7851448 
          Median |        44      11.58   .8458362 
              Q3 |        68      17.89   .8971391 
             Max |       151      39.74          1 
    -----------------------------------------------

    Comment


    • #3
      With thanks to Kit Baum, we have updated the commands on SSC. The following changes were made:
      1. aei default tolerance is 10^-6 instead of 10^-12
      2. aei is now more stable and faster for tolerance levels up to 10^-15
      3. For ease of initial use, we added the example dataset as an ancillary file to the package. This means that the data can be accessed by typing "net get rpaxioms" and it will be downloaded to your current working directory.
      4. Help-files now include examples and illustrations
      5. Miscellaneous aesthetic changes (e.g. report result of fraction of violations now in decimal)
      A good way to get acquainted with these changes is to first run
      Code:
      ssc install rpaxioms
      then read through the help-file of checkax
      Code:
      help checkax
      /Marcos


      Comment

      Working...
      X