Announcement

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

  • How to extract coefficients from saved results in "cointreg" package?

    Dear all,

    I am using -cointreg- from SSC in Stata 14. I have a panel dataset. However, I'm estimating FMOLS for each country/id.
    The command - cointreg - saves its results in e(). The coefficient vector is stored in e(b). The FMOLS gives a long-run coefficient and intercept.


    . cointreg gcf gds if id==1, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn

    Cointegration regression (FMOLS):

    VAR lag(user) = 1 Number of obs = 46
    Kernel = qs R2 = .2646553
    Bandwidth(andrews) = 1.5709 Adjusted R2 = .2479429
    S.e. = 3.724559
    Long run S.e. = 7.48136

    ------------------------------------------------------------------------------
    gcf | Coef. Std. Err. z P>|z| [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    gds | .9979715 .2491818 4.00 0.000 .5095841 1.486359
    _cons | -1.91057 5.525475 -0.35 0.730 -12.7403 8.919162
    ------------------------------------------------------------------------------

    . eret li

    scalars:
    e(N) = 46
    e(r2) = .2646552666919184
    e(r2_a) = .2479428863894621
    e(rmse) = 3.724559297317706
    e(lrse) = 7.481359939435503
    e(rss) = 610.3830462063735
    e(tss) = 830.0638034904455
    e(eqtrend) = 0
    e(xtrend) = 0
    e(bwidth) = 1.5708772426484
    e(vlag) = 1

    macros:
    e(cmd) : "cointreg"
    e(cmdline) : "cointreg gcf gds if id==1, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(a.."
    e(est) : "fmols"
    e(vic) : "user"
    e(bmeth) : "andrews"
    e(kernel) : "qs"
    e(properties) : "b V"
    e(depvar) : "gcf"

    matrices:
    e(b) : 1 x 2
    e(V) : 2 x 2

    In order to export results to a spreadsheet, I use "runby" command. I want to extract both the coefficients ( gds and con in the above table). For this I write the following programme:

    Code:
    clear all
    program my_results
      tsset year
      cointreg gcf gds, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
      gen adj_r2=`e(r2_a)'
      gen method="`e(est)'"
      gen N=`e(N)'
      gen coef_gds=`e(b_1)'
      gen coef_con=`e(b_2)'
      keep in 1
     end
    However, there is something wrong with generating the coefficients in the above program. It is because I do not know how to generate.
    I also want to extract corresponding t-stats and p-values of both the coefficients. How to generate them?

    I would be grateful if you can kindly help me.

    Thank you in advance.
    Last edited by Santosh Dash; 13 Apr 2019, 03:13.

  • #2
    Because this is an estimation command, I would use esttab from Stata Journal. This is not tested as I have not installed the command.

    Code:
    tempfile data
    save `data'
    levelsof id, local(ids)
    
    foreach id in `ids'{
    keep if id==`id'
    cointreg gcf gds, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
    eststo est`id'
    use `data', clear
    }
    
    esttab est* using myfile.csv, stats(N r2)

    Comment


    • #3
      Thank you for your reply. I ran your code as follows:

      Code:
      use wdi_fhp
      levelsof id, local(ids)
      
      foreach id in `ids'{
      keep if id==`id'
      cointreg gcf gds, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
      eststo est `id'
      use `wdi_fhp', clear
      }
      *
      esttab est* using myfile.csv, stats(N r2)
      Stata returned the following error:
      estimation result est* not found
      r(111);

      With regard to my question in #1, there is a simple way to generate coefficients and its corresponding standard errors.

      Code:
      clear all
      program my_results
        tsset year
        cointreg gcf gds, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
        gen adj_r2=`e(r2_a)'
        gen method="`e(est)'"
        gen N=`e(N)'
        gen lrc=_b[gds]
        gen lrc_se=_se[gds]
        gen lrc_z=lrc/lrc_se
        keep in 1
       end
      This code works fine. However, I'm struggling to generate p-values of the coefficient.
      I was trying this code:

      Code:
      gen p_value=2 * ttail(e(df_r), abs(_b[gds]/_se[gds])))
      However, -cointreg- does not retrun e(df_r).

      Can you kindly help me?
      Thank you.

      Comment


      • #4
        In #3, I asked about generating p-values. I could fix it now. I did not recognise that the distribution is z-distribution, while the code i was trying was for t-distribution.
        However, with regard to esstab, I am not able to do.

        I also tried with the outreg2 command:

        Code:
        foreach i of numlist 1/8 {
        tab ic country if id==`i'
        cointreg gcf gds if id==`i', est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
        outreg2 using ABC, excel dec(3) br
        }
        *
        It is creating the following error:
        file ABC.xml is read-only; cannot be modified or erased
        The file needs to be closed if being used by another software such as Excel.
        r(608);


        However, if I am removing the word "excel" in the outrge2 line in the loop, all the results are coming nicely in a text file. However, I WANT TO EXPORT RESULTS TO A SPREADSHEET.

        I would be grateful if you can kindly help me with this.

        Comment


        • #5
          Stata returned the following error:
          estimation result est* not found
          r(111);

          Code:
          use wdi_fhp
          tempfile data
          save `data'
          levelsof id, local(ids)
          foreach id in `ids'{
          keep if id==`id'
          cointreg gcf gds, est(fmols) eqtrend(0) vlag(1) kernel(qs) bmeth(andrews) nodivn
          eststo est `id'
          use `data', clear
          }
          esttab est* using myfile.csv, stats(N r2)
          It is creating the following error:
          file ABC.xml is read-only; cannot be modified or erased
          The file needs to be closed if being used by another software such as Excel.
          r(608);
          You probably have a file with the same name open somewhere which you need to close before running the program. In any case, if you are taking lags, you have to be careful when using the if qualifier as the lag term under tsset does not recognize the panel structure of your data.

          Comment

          Working...
          X