Announcement

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

  • export Ips unit root test results in stata to latex

    I am trying to figure out a command to save my IPS unit root test results in a tex form. esttab, estout not working. tried asdoc but cannot seem to get it right. anyone to please help me with the series of commands. I would like to export z statistic and p values. Thank you.

  • #2
    This command does not store anything in e(), so you can write a program that transfers the relevant results from r() to e(). The variable name is not stored anywhere, so you will have to insert this manually (highlighted). Below, I use estout from SSC. You can add more results to the program, see

    Code:
    return list
    after running the command.


    Code:
    cap prog drop xtunitroot2e
    prog def xtunitroot2e, eclass
    ereturn clear
    matrix wtbar= J(1, 1, r(wtbar))
    matrix p=J(1, 1, r(p_wtbar))
    ereturn scalar Panels= r(N_g)
    ereturn scalar Periods= r(N_t)  
    ereturn mat Statistic= wtbar
    ereturn mat p_S=p
    end
    
    
    webuse pennxrate, clear
    xtunitroot ips lnrxrate, lags(aic 5)
    
    xtunitroot2e
    esttab, cells(Statistic(star pval(p_S))) noobs nonumb ///
    stats(Panels Periods) coeflab(c1 "lnrxrate") mlab(none) ///
    collab(, lhs(Variable)) addnote("* p<0.05, ** p<0.01, *** p<0.001") tex
    Res.:

    Code:
    . xtunitroot2e
    
    . esttab, cells(Statistic(star pval(p_S))) noobs nonumb ///
    > stats(Panels Periods) coeflab(c1 "lnrxrate") mlab(none) ///
    > collab(, lhs(Variable)) addnote("* p<0.05, ** p<0.01, *** p<0.001") tex
    
    {
    \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
    \begin{tabular}{l*{1}{c}}
    \hline\hline
    Variable    &   Statistic         \\
    \hline
    lnrxrate    &    -15.2812\sym{***}\\
    \hline
    Panels      &         151         \\
    Periods     &          34         \\
    \hline\hline
    \multicolumn{2}{l}{\footnotesize * p<0.05, ** p<0.01, *** p<0.001}\\
    \end{tabular}
    }

    Comment


    • #3
      Dear Andrew, Thanks for this. However, I used the command below to generate a loop. Wondering if you could help me with a command to save the output into latex or in a tex format. Thank you.

      gen variable=""
      gen double pvalue=.
      gen panels=.
      gen Tbar=.
      local i 1
      foreach var of varlist lgdp populationgrowth lle lgfca lumem{
      xtunitroot ips `var',trend
      replace variable= subinstr("`var'","_", " ", .) in `i'
      replace panels= r(N_g) in `i'
      replace Tbar = r(tbar) in `i'
      replace pvalue= r(p_zttildebar) in `i'
      local ++i
      }
      format pvalue Tbar %9.3f
      drop if missing(variable)
      keep variable pvalue panels Tbar
      list, clean



      Comment


      • #4
        See texsave from SSC.

        Code:
        ssc install texsave, replace


        Code:
        [*CODE]
        keep variable pvalue panels Tbar
        texsave * using myfile.tex, replace

        Comment


        • #5
          Thank you so much Andrew. This worked

          Comment


          • #6
            Hi Andrew, just a follow up, is there a command using texsave that would identify significant pvalues in asterisk, just as in esttab? If not, is there an alternative approach to have significant pvalues highlighted in *? Thank you.

            Comment


            • #7
              Attaching the stars to the statistics should not be difficult.

              Code:
              clear
              input float (stat pval)
              6.135 0.013
              15.227 0.0001
              120.290 0.78
              2.222 0.075
              end
              
              gen wanted= cond(pval<0.01, string(stat, "%5.3f")+ "***", ///
                  cond(inrange(pval, 0.01, 0.05), string(stat, "%5.3f")+"**", ///
                      cond(inrange(pval, 0.05, 0.1), string(stat, "%5.3f")+"*", string(stat, "%5.3f"))))
              Res.:

              Code:
              . order stat wanted
              
              . l
              
                   +----------------------------+
                   |   stat      wanted    pval |
                   |----------------------------|
                1. |  6.135     6.135**    .013 |
                2. | 15.227   15.227***   .0001 |
                3. | 120.29     120.290     .78 |
                4. |  2.222      2.222*    .075 |
                   +----------------------------+

              Comment


              • #8
                Thank you Andrew

                Comment


                • #9
                  I'm not sure whether the asterisks will be superscripted when exporting to LaTeX. If not, you'll need:

                  Code:
                  clear
                  input float (stat pval)
                  6.135 0.013
                  15.227 0.0001
                  120.290 0.78
                  2.222 0.075
                  end
                  
                  gen wanted= cond(pval<0.01, string(stat, "%5.3f")+ "$^{***}$", ///
                                            cond(inrange(pval, 0.01, 0.05), string(stat, "%5.3f")+"$^{**}$", ///
                                                cond(inrange(pval, 0.05, 0.1), string(stat, "%5.3f")+"$^{*}$", string(stat, "%5.3f"))))
                  Res.:

                  Code:
                  . order stat wanted
                  
                  . l
                  
                       +---------------------------------+
                       |   stat           wanted    pval |
                       |---------------------------------|
                    1. |  6.135     6.135$^{**}$    .013 |
                    2. | 15.227   15.227$^{***}$   .0001 |
                    3. | 120.29          120.290     .78 |
                    4. |  2.222      2.222$^{*}$    .075 |
                       +---------------------------------+

                  Comment


                  • #10
                    ok noted Andrew Thank you. How about cross sectional dependence results? I'd like to generate a latex format table with significant variables indicated by asterisk

                    texsave does not seem to generate the right table.

                    command is xtcdf lgdp lle lumem populationgrowth lgfca.

                    Comment


                    • #11
                      I have not used xtcdf (SSC) before. Perhaps start a new thread and those familiar with that command can respond.

                      Comment


                      • #12
                        ok Thank you

                        Comment

                        Working...
                        X