Announcement

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

  • How to get a formated table of statistics from a stationarity test in a 40 variable loop

    I want to conduct a stationarity test (Fisher) for around 40 variables in my data. I have managed to put this in a loop but unfortunately, outreg2 is not enabled to pull the stats and most likely the test routine does not store these stats. Here is my loop;

    Code:
    foreach var of varlist gross_loan_portfolio - donated_equity{
    set more off
    display "**********************************"
    display `var'
    display "**********************************"
    xtunitroot fisher gross_loan_portfolio, dfuller trend lags(0)
    }
    A MWE data is here (note some vars have been left out);

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(debt_to_equity_ratio impairment_loss_allowance portfolio_at_risk30_days operating_expense operational_self_sufficiency profit_margin deposits_to_loans secondarygross)
     2.82   2377547 .0106  12238901 1.7445   .4268      .   81.033
     2.91   2252613 .0106  18663047 1.2542   .2027      . 81.65817
      2.7   7158780 .0106  21758087 1.2523   .2015      . 82.48176
     2.94   3590827 .0106  39693333 1.2229   .1823      . 83.49302
     2.86   5583411 .0106  45364117 1.1556   .1347      . 85.96943
       .7   5296718 .1011  61363333 1.2159   .1776  .6403 85.96943
     1.22  15016045 .1735  78381661 1.2603   .2066 1.1142 87.39671
      .96  15383773 .1158  88034398 1.2884   .2239  .9947 90.64883
     1.41  22398964 .1125 112489124 1.2717   .2137  .6971 92.33537
     2.53  25339229 .1011 122135328 1.2323   .1885  .4875  90.8974
     4.49  49525000 .1011 171181704 1.2399   .1935  .6231  92.5119
     3.18 121368678 .0601 250691425  1.234   .1896  .6575  93.7372
     3.56 206860241 .0601 339197544  1.267   .2108  .6169 96.18246
      3.5 303546711 .0601 359102262 1.2666   .2105  .6169 98.82686
    -5.12     15699   .04    245146  .4722 -1.1176      0 84.58689
    -1.89     20219   .04    358119  .4058 -1.1176      0   81.033
     -2.2     22596   .02    402680  .4281 -1.3359      0 81.65817
    -1.85    179347   .16    412950  .2685 -2.7249      0 82.48176
    -1.05         0  .095     96857  .1025  -8.752      0 81.65817
    -1.23         0   .08    126564  .2086 -3.7929      0 82.48176
    end

    How can I ensure that I pull at least the variable name, the p-value, number of panels and the Inverse Chi?

  • #2
    With frames, you can save the results in a frame and thereafter export them in whatever format you like. Here is an illustration based on your data example. I create a panel identifier and time variable which are missing.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input double(debt_to_equity_ratio impairment_loss_allowance portfolio_at_risk30_days operating_expense operational_self_sufficiency profit_margin deposits_to_loans secondarygross)
     2.82   2377547 .0106  12238901 1.7445   .4268      .   81.033
     2.91   2252613 .0106  18663047 1.2542   .2027      . 81.65817
      2.7   7158780 .0106  21758087 1.2523   .2015      . 82.48176
     2.94   3590827 .0106  39693333 1.2229   .1823      . 83.49302
     2.86   5583411 .0106  45364117 1.1556   .1347      . 85.96943
       .7   5296718 .1011  61363333 1.2159   .1776  .6403 85.96943
     1.22  15016045 .1735  78381661 1.2603   .2066 1.1142 87.39671
      .96  15383773 .1158  88034398 1.2884   .2239  .9947 90.64883
     1.41  22398964 .1125 112489124 1.2717   .2137  .6971 92.33537
     2.53  25339229 .1011 122135328 1.2323   .1885  .4875  90.8974
     4.49  49525000 .1011 171181704 1.2399   .1935  .6231  92.5119
     3.18 121368678 .0601 250691425  1.234   .1896  .6575  93.7372
     3.56 206860241 .0601 339197544  1.267   .2108  .6169 96.18246
      3.5 303546711 .0601 359102262 1.2666   .2105  .6169 98.82686
    -5.12     15699   .04    245146  .4722 -1.1176      0 84.58689
    -1.89     20219   .04    358119  .4058 -1.1176      0   81.033
     -2.2     22596   .02    402680  .4281 -1.3359      0 81.65817
    -1.85    179347   .16    412950  .2685 -2.7249      0 82.48176
    -1.05         0  .095     96857  .1025  -8.752      0 81.65817
    -1.23         0   .08    126564  .2086 -3.7929      0 82.48176
    end
    
    gen id= cond(_n<11, 1, 2)
    gen time=cond(_n<11, _n, _n-10)
    xtset id time
    
    *START HERE
    frame create results
    frame results{
        set obs 8
        gen variable=""
        gen double pvalue=.
        gen panels=.
        gen Chi2=.
    }
    local i 1
    foreach var of varlist debt_to_equity_ratio -secondarygross{
        xtunitroot fisher `var', dfuller trend lags(0)
        frame results{
            replace variable= "`var'" in `i'
            replace panels= r(N_g) in `i'
            replace Chi2 = r(P) in `i'
            replace pvalue= r(p_P) in `i'
        }
        local ++i
    }
    frame results: format pvalue Chi2 %9.3f
    frame results: list, sep(10)
    Res.:

    Code:
    . frame results: list, sep(10)
    
         +---------------------------------------------------------+
         |                     variable   pvalue   panels     Chi2 |
         |---------------------------------------------------------|
      1. |         debt_to_equity_ratio    0.866        2    1.270 |
      2. |    impairment_loss_allowance    0.617        2    2.655 |
      3. |     portfolio_at_risk30_days    0.444        2    3.732 |
      4. |            operating_expense    0.553        2    3.032 |
      5. | operational_self_sufficiency    0.000        2   65.772 |
      6. |                profit_margin    0.000        2   37.361 |
      7. |            deposits_to_loans    0.000        2   38.397 |
      8. |               secondarygross    0.524        2    3.207 |
         +---------------------------------------------------------+

    Comment


    • #3
      Thanks Andrew. However, could there be a reason why my frame command returns an error that the command is unrecognized? Have tried to look for an installation but I think frame is a not user written?

      Comment


      • #4
        frames were introduced in Stata 16, so you won't have access to this command with earlier versions of Stata. It is still however possible to store the results in the current dataset.

        Code:
         * Example generated by -dataex-. To install: ssc install dataex
        clear
        input double(debt_to_equity_ratio impairment_loss_allowance portfolio_at_risk30_days operating_expense operational_self_sufficiency profit_margin deposits_to_loans secondarygross)
         2.82   2377547 .0106  12238901 1.7445   .4268      .   81.033
         2.91   2252613 .0106  18663047 1.2542   .2027      . 81.65817
          2.7   7158780 .0106  21758087 1.2523   .2015      . 82.48176
         2.94   3590827 .0106  39693333 1.2229   .1823      . 83.49302
         2.86   5583411 .0106  45364117 1.1556   .1347      . 85.96943
           .7   5296718 .1011  61363333 1.2159   .1776  .6403 85.96943
         1.22  15016045 .1735  78381661 1.2603   .2066 1.1142 87.39671
          .96  15383773 .1158  88034398 1.2884   .2239  .9947 90.64883
         1.41  22398964 .1125 112489124 1.2717   .2137  .6971 92.33537
         2.53  25339229 .1011 122135328 1.2323   .1885  .4875  90.8974
         4.49  49525000 .1011 171181704 1.2399   .1935  .6231  92.5119
         3.18 121368678 .0601 250691425  1.234   .1896  .6575  93.7372
         3.56 206860241 .0601 339197544  1.267   .2108  .6169 96.18246
          3.5 303546711 .0601 359102262 1.2666   .2105  .6169 98.82686
        -5.12     15699   .04    245146  .4722 -1.1176      0 84.58689
        -1.89     20219   .04    358119  .4058 -1.1176      0   81.033
         -2.2     22596   .02    402680  .4281 -1.3359      0 81.65817
        -1.85    179347   .16    412950  .2685 -2.7249      0 82.48176
        -1.05         0  .095     96857  .1025  -8.752      0 81.65817
        -1.23         0   .08    126564  .2086 -3.7929      0 82.48176
        end
        
        gen id= cond(_n<11, 1, 2)
        gen time=cond(_n<11, _n, _n-10)
        xtset id time
        *START HERE
        preserve
        gen variable=""
        gen double pvalue=.
        gen panels=.
        gen Chi2=.
        local i 1
        foreach var of varlist debt_to_equity_ratio -secondarygross{
            xtunitroot fisher `var', dfuller trend lags(0)
            replace variable= subinstr("`var'","_", " ", .)  in `i'
            replace panels= r(N_g) in `i'
            replace Chi2 = r(P) in `i'
            replace pvalue= r(p_P) in `i'
            local ++i
        }
        format pvalue Chi2 %9.3f
        drop if missing(variable)
        keep variable pvalue panels Chi2
        list, clean
        After exporting the results, restore to revert to the original dataset.


        Code:
        . list, clean
        
                                   variable   pvalue   panels     Chi2  
          1.           debt to equity ratio    0.866        2    1.270  
          2.      impairment loss allowance    0.617        2    2.655  
          3.       portfolio at risk30 days    0.444        2    3.732  
          4.              operating expense    0.553        2    3.032  
          5.   operational self sufficiency    0.000        2   65.772  
          6.                  profit margin    0.000        2   37.361  
          7.              deposits to loans    0.000        2   38.397  
          8.                 secondarygross    0.524        2    3.207
        Last edited by Andrew Musau; 15 Jul 2020, 01:18.

        Comment


        • #5
          Ooops! Still stuck on Version 14. But thanks a lot for this alternative. Works well!

          Comment


          • #6
            You can use asdoc (from SSC, recent version from my site) for this. I have modified Andrew Musau code for asdoc.
            The new version of asdoc can be installed from my site. Copy and paste the following line in Stata and press enter.

            Code:
            net install asdoc, from(http://fintechprofessor.com) replace
            
            asdoc, row(variable, panels, Chi2, pvalue) replace
            
            local i 1
            
            foreach var of varlist debt_to_equity_ratio -secondarygross{
                xtunitroot fisher `var', dfuller trend lags(0)
                loc obs = `r(N_g)'
                loc chi = `r(P)'
                loc pva = `r(p_P)'
              
                asdoc, row(`var', `obs', `chi', `pva')    
                local ++i
            }
            It produces the following table.
            Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	47.2 KB
ID:	1563806




            More on asdoc can be read here
            https://fintechprofessor.com/2018/01/31/asdoc/

            asdocx is now avaialble
            A more powerful and flexible version of asdoc is now available. I call it asdocx. You may like to check the details here

            https://fintechprofessor.com/asdocx


            Please do remember to cite asdoc. To cite:

            In-text citation
            Tables were created using asdoc, a Stata program written by Shah (2018).

            Bibliography
            Shah, A. (2018). ASDOC: Stata module to create high-quality tables in MS Word from Stata output. Statistical Software Components S458466, Boston College Department of Economics.
            Last edited by Attaullah Shah; 16 Jul 2020, 12:50.
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              Dear Attaullah,

              Thank you for this code. In fact it is very helpful also for my research. However, and in addition to your post, I would request some help of you as I am a begginer with STATA. I am trying to assess if by public debt over GDP variable (among other variables) has a unit root in an (unbalanced) panel data covering more than 100 countries between 1970 and 2018. However, I would like to check the unit roots for the variables for each individual country as made in the article "The elusive character of fiscal sustainability", for instance. I could indeed replicate your code to my case by I am not reaching the solution of how to make the unit root tests by countries. Could you help me? Thank you in advance.

              Click image for larger version

Name:	Image.png
Views:	1
Size:	137.5 KB
ID:	1601263

              Comment


              • #8
                You can post a sample of your data using dataex and then indicate how would you like the output table to look like?
                Regards
                --------------------------------------------------
                Attaullah Shah, PhD.
                Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                FinTechProfessor.com
                https://asdocx.com
                Check out my asdoc program, which sends outputs to MS Word.
                For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                Comment


                • #9
                  Dear Attaullah,

                  Thank you for your quick reply. I am very noob in these stufs, so I upload the excel file of my data containing debt_gdp variable. I would like to get a table similary to the code you proposed but for each country of my database. I mean, in rows should appear the countries, then in collumns the values of the statistics (chi2 and pvalues) associated to the unitroot tests for each country. Do you understand? Thank you once again.
                  Attached Files

                  Comment


                  • #10
                    Dear Attaullah, (@attaullah shah)
                    What if you are using a different unit root test? For example, IPS test for panel data. What will be the code to implement with such a case? I tried using ips instead of fisher but could not get the results. Thanking you in advance.

                    Comment


                    • #11
                      Dear Attaullah,

                      Are you able to modify the commands in #6 to create a latex or tex file instead of a word document? Thank you

                      Comment

                      Working...
                      X