Announcement

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

  • Error: unknown function ()

    Hello everyone,

    I am trying to compute tariff equivalent effects following the approach suggested in An Advanced Guide to Trade Policy Analysis. page 30 of the book. I attach below the code proposed in the book and the error I get when I try the second line of the code:

    Code:
    *** Model for GVC participation
    asdoc ppmlhdfe gvc_total regulatory_distance contig applied_tariff ln_dist comlang_off comlang_ethno comcol comrelig col45 comleg_pretrans sibling rta if exp!=imp, a(exp_time imp_time) vce(cluster pair_id) replace
    
    * Tariff equivalent effects
    scalar TariffEquivalentRD_1 = (exp(_b[regulatory_distance]/(-_b[applied_tariff])) – 1) * 100
    
    unknown function ()
    r(133);

    Does someone know how to fix this issue?

    Thanks in advance

  • #2
    Alessio:
    have you already double-checked number and order of brackets?
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Dear Carlo,
      thank you very much for the prompt reply. Yes, I have checked the number of brackets and it is not wrong. Also, I tried to delete the first pair of parenthesis and I got the following issue:

      Code:
      . scalar TariffEquivalentRD_1 = exp(_b[regulatory_distance]/(-_b[applied_tariff]
      > )) – 1 
      invalid '–'

      Comment


      • #4
        I guess that you can write the expression as follows:

        Code:
        scalar TariffEquivalentRD_1 = (`=exp(_b[regulatory_distance]/(-_b[applied_tariff])) -1')*100

        It appears that scalar is unable to directly evaluate the expression as written.
        Last edited by Andrew Musau; 21 Jul 2021, 06:57.

        Comment


        • #5
          Dear Andrew,

          thank you very much for your help. I followed your suggestion and the code as you proposed seems to work. However, I am not sure about what I get. Normally, it should yield a positive or negative percentage. I tried it with different models and I always get this result. Is it possible that there is an error?

          Code:
          . di TariffEquivalentRD_1
          -100
          Thank again for your support

          Comment


          • #6
            In performing arithmetic operations, order matters, hence the acronyms PEMDAS (Parenthesis Exponents Multiplication Division Addition Subtraction), BODMAS (Brackets Orders Division Multiplication Addition Subtraction), BIDMAS (Brackets Indices Division Multiplication Addition Subtraction), etc. All these imply the same order of operations. So you can verify whether you are getting a sensible result based on how you expect the expression to be evaluated. Therefore, if you want to substract before multiplying, then parenthesize the elements to be subtracted. Substituting regulatory_distance with "weight" and applied_tariff with "trunk", I get

            Code:
            sysuse auto, clear
            regress mpg weight trunk
            scalar test = (`=exp(_b[weight]/(-_b[trunk])) -1')*100
            di test
            Res.:

            Code:
            . regress mpg weight trunk
            
                  Source |       SS           df       MS      Number of obs   =        74
            -------------+----------------------------------   F(2, 71)        =     67.19
                   Model |  1598.76953         2  799.384767   Prob > F        =    0.0000
                Residual |  844.689926        71  11.8970412   R-squared       =    0.6543
            -------------+----------------------------------   Adj R-squared   =    0.6446
                   Total |  2443.45946        73  33.4720474   Root MSE        =    3.4492
            
            ------------------------------------------------------------------------------
                     mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
            -------------+----------------------------------------------------------------
                  weight |  -.0056527   .0007016    -8.06   0.000    -.0070516   -.0042537
                   trunk |   -.096229   .1274771    -0.75   0.453    -.3504112    .1579531
                   _cons |   39.68913    1.65207    24.02   0.000       36.395    42.98327
            ------------------------------------------------------------------------------
            
            
            
            . scalar test = (`=exp(_b[weight]/(-_b[trunk])) -1')*100
            
            .
            . di test
            -5.7049911
            which seems to be right as

            [exp(-.0056527/0.096229)]- 1 = -.05705014 and (-.05705014*100)\(\approx\) -5.705.
            Last edited by Andrew Musau; 21 Jul 2021, 09:33.

            Comment


            • #7
              Dear Andrew,
              thank you very much for your detailed and comprehensive explanation. See the code attached below:

              Code:
               regress gvc_total regulatory_distance applied_tariff
              
                    Source |       SS           df       MS      Number of obs   =   582,015
              -------------+----------------------------------   F(2, 582012)    =    167.21
                     Model |  70713332.2         2  35356666.1   Prob > F        =    0.0000
                  Residual |  1.2307e+11   582,012  211454.026   R-squared       =    0.0006
              -------------+----------------------------------   Adj R-squared   =    0.0006
                     Total |  1.2314e+11   582,014  211574.797   Root MSE        =    459.84
              
              -------------------------------------------------------------------------------
                  gvc_total |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              --------------+----------------------------------------------------------------
              regulatory_~e |   39.87936   7.115612     5.60   0.000     25.93299    53.82573
              applied_tar~f |  -1.098885   .0603646   -18.20   0.000    -1.217198   -.9805724
                      _cons |    56.6861   1.004809    56.41   0.000      54.7167    58.65549
              -------------------------------------------------------------------------------
              
              . 
              end of do-file
              
              . do "C:\Users\Utente\AppData\Local\Temp\STD4478_000000.tmp"
              
              . scalar TariffEquivalentRD = (`=exp(_b[regulatory_distance]/(-_b[applied_tariff
              > ])) -1') * 100
              
              . 
              end of do-file
              
              . do "C:\Users\Utente\AppData\Local\Temp\STD4478_000000.tmp"
              
              . di TariffEquivalentRD
              5.766e+17
              
              . 
              end of do-file
              
              . do "C:\Users\Utente\AppData\Local\Temp\STD4478_000000.tmp"
              
              . regress gvc_total regulatory_distance applied_tariff
              
                    Source |       SS           df       MS      Number of obs   =   582,015
              -------------+----------------------------------   F(2, 582012)    =    167.21
                     Model |  70713332.2         2  35356666.1   Prob > F        =    0.0000
                  Residual |  1.2307e+11   582,012  211454.026   R-squared       =    0.0006
              -------------+----------------------------------   Adj R-squared   =    0.0006
                     Total |  1.2314e+11   582,014  211574.797   Root MSE        =    459.84
              
              -------------------------------------------------------------------------------
                  gvc_total |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
              --------------+----------------------------------------------------------------
              regulatory_~e |   39.87936   7.115612     5.60   0.000     25.93299    53.82573
              applied_tar~f |  -1.098885   .0603646   -18.20   0.000    -1.217198   -.9805724
                      _cons |    56.6861   1.004809    56.41   0.000      54.7167    58.65549
              -------------------------------------------------------------------------------
              
              . 
              end of do-file
              
              . do "C:\Users\Utente\AppData\Local\Temp\STD4478_000000.tmp"
              
              . scalar TariffEquivalentRD = (`=exp(_b[regulatory_distance]/(-_b[applied_tariff
              > ])) -1') * 100
              
              . di TariffEquivalentRD
              5.766e+17
              
              . 
              end of do-file
              
              . do "C:\Users\Utente\AppData\Local\Temp\STD4478_000000.tmp"
              
              . qui asdoc ppmlhdfe gvc_total regulatory_distance contig applied_tariff ln_dist
              >  comlang_off comlang_ethno comcol comrelig col45 comleg_pretrans sibling rta i
              > f exp!=imp, a(exp_time imp_time industry) vce(cluster pair_id) replace
              
              . scalar TariffEquivalentRD = (`=exp(_b[regulatory_distance]/(-_b[applied_tariff
              > ])) -1') * 100
              
              
              . di TariffEquivalentRD
              -100
              Might it be possible that the issue is related to the model ppmlhdfe ?
              Thanks again for your time!

              Comment


              • #8
                Look at the coefficients


                Code:
                di _b[regulatory_distance]
                di _b[applied_tariff]

                If the numerator is large relative to the denominator, taking the exponential of the ratio will result in a value close to or equal to 0. Then you will observe your result, e.g.,

                Code:
                 di exp(-1000/ 1.2)
                Res.:

                Code:
                . di exp(-1000/ 1.2)
                0
                Last edited by Andrew Musau; 21 Jul 2021, 10:54.

                Comment


                • #9
                  Dear Andrew,
                  I am afraid you are right, the numerator is indeed large compared to the numerator. I guess I cannot really use the estimates I get and I cannot overcome this issue.
                  Thank you very much for your help

                  Comment


                  • #10
                    You can change the magnitude of a coefficient by rescaling the variable. This changes nothing except the units of the variable.

                    Code:
                    sysuse auto, clear
                    regress mpg trunk weight
                    replace weight= weight/1000
                    regress mpg trunk weight
                    Res.:

                    Code:
                    . regress mpg trunk weight
                    
                          Source |       SS           df       MS      Number of obs   =        74
                    -------------+----------------------------------   F(2, 71)        =     67.19
                           Model |  1598.76953         2  799.384767   Prob > F        =    0.0000
                        Residual |  844.689926        71  11.8970412   R-squared       =    0.6543
                    -------------+----------------------------------   Adj R-squared   =    0.6446
                           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4492
                    
                    ------------------------------------------------------------------------------
                             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                           trunk |   -.096229   .1274771    -0.75   0.453    -.3504112    .1579531
                          weight |  -.0056527   .0007016    -8.06   0.000    -.0070516   -.0042537
                           _cons |   39.68913    1.65207    24.02   0.000       36.395    42.98327
                    ------------------------------------------------------------------------------
                    
                    .
                    . replace weight= weight/1000
                    variable weight was int now float
                    (74 real changes made)
                    
                    .
                    . regress mpg trunk weight
                    
                          Source |       SS           df       MS      Number of obs   =        74
                    -------------+----------------------------------   F(2, 71)        =     67.19
                           Model |  1598.76956         2  799.384782   Prob > F        =    0.0000
                        Residual |  844.689895        71  11.8970408   R-squared       =    0.6543
                    -------------+----------------------------------   Adj R-squared   =    0.6446
                           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4492
                    
                    ------------------------------------------------------------------------------
                             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                           trunk |   -.096229   .1274771    -0.75   0.453    -.3504112    .1579531
                          weight |  -5.652679   .7015899    -8.06   0.000     -7.05161   -4.253749
                           _cons |   39.68913    1.65207    24.02   0.000       36.395    42.98327
                    ------------------------------------------------------------------------------
                    
                    .

                    Comment

                    Working...
                    X