Announcement

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

  • Exporting outputs from Stata to word or excel

    Dear experts,
    I kindly ask you to help on how I export couple of outputs from Stata. The first is, I want to export a matrix from decomposition analysis between time periods. Last time, I posted a similar post on how to export a newly generated variable. But, here, I would like to ask the same question but these variables need to be exported using matrix
    Code:
    qui sum anc_quality_binary if survey==4 [aw=wt]
    sca m_y=r(mean)
    svy: qui glm anc_quality_binary $X if survey==4, family(binomial) link(logit)
     
     
    foreach x of varlist $X {
    sca b_`x'=_b[`x']
     
    }
     
    foreach x of varlist $X {
    qui {
    conindex `x' if survey==4, rank(swpatt3gr) truezero svy
    gen CI16_`x' = r(CI)
    sum `x' if survey==4 [aw=wt]
    sca m_`x'=r(mean)
    gen elas16_`x' = (b_`x'*m_`x')/m_y
    sca con_`x' = 4*b_`x'*m_`x'*CI16_`x'
    sca prcnt_`x' = 100*con_`x'/EI16
    gen CC`x' = elas16_`x'*(CI16_`x' - CI00_`x') + CI00_`x'*(elas16_`x' - elas00_`x')
    gen CE`x' = elas00_`x'*(CI16_`x' - CI00_`x') + CI16_`x'*(elas16_`x' - elas00_`x')
    gen cha_Ela`x' = elas16_`x' - elas00_`x'
    gen cha_C`x' = CI16_`x' - CI00_`x'
    }
    di "`xí elasticity 1:", elas16_`x'
    di "`xí elasticity 2:",  elas00_`x'
    di "`xí concentration index 3:", CI16_`x'
    di "`xí concentration index 4:", CI00_`x'
    di "`xí contribution to change 5:", CC`x'
    di "`xí chnage in Ela 6:", cha_Ela`x'
    di "`xí chnage in CI 7:", cha_C`x'
    matrix qu_nm = nullmat(qu_nm)\ (elas16_`x', elas00_`x', CI16_`x', CI00_`x', CC`x', cha_Ela`x', cha_C`x')
    }
    matrix rownames qu_nm= $X
    matrix colnames qu_nm = "elasticity 1""elasticity 2""concentration index 3""concentration index 4""contribution to change 5""chnage in Ela 6""chnage in CI 7"
    matrix list qu_nm , format(%8.3f)
    The problem I faced is on the matrix (towards the end of the code).

    My second question is related to exporting cross tabulation of many variables at once in one big table. That, is I want to do cross tabulations between all of my exposure variables with an outcome variable and exporting all of them once. I tried using tabout ( see below) but the code gives me weighted count only, not the number of observations in each cell of the cross tabulation.

    Code:
    tabout at_birth_for_PNC region v106_new husband_edu_new v190 women_occupation husband_occupation religion_f_pnc religion_f media_new wantedness_child swpatt3gr swpsoc3gr swpdec3gr birthor PNC_skiiled2 using tablePNC2011Urban.xls if survey==4 & v025==2, cells(freq) format(0 1) clab(No. Col_% Cum_%) svy rep

    The last variable, PNC_skiiled2, is outcome variable and the other are exposures. Do you help how I also or ,instead of weighted count, present number of observations for each cell in the cross tabulation in this code
    or other similar code?

    If I get an automatic export method, it would save me a lot of time and energy.

    Thank you in advance.
    Last edited by Gebretsadik Shibre; 04 Jun 2023, 12:14.

  • #2
    Try looking at the community-contributed command outreg2

    Comment


    • #3
      The table requirements in your posts are very similar to that produced by the table1 template of asdocx, see this example https://fintechprofessor.com/asdocx/...tients-asdocx/
      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

      Working...
      X