Announcement

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

  • Descriptive Statistic for Categorical Variable

    Hi all,

    I am trying to create a table of descriptive statistics for my explanatory variables, one of which is Industry Classification. I want the summary statistic to break it down by industry but my current code, as shown below, is failing.

    Code:
    sum BICSLevel1_n=="Communications" BICSLevel1_n="Consumer Discretionary" BICSLevel1_n="Consumer Staples" BICSLevel1_n="Energy "BICSLevel1_n="Financials" BICSLevel1_n="Health Care" BICSLevel1_n="Industrials" BICSLevel1_n="Materials" BICSLevel1_n="Technology" BICSLevel1_n="Utilities" LoanTrancheSizeBM LoanTrancheSizeAM OriginalMaturityBM OriginalMaturityAM AverageLifeBM AverageLifeAM CouponBM CouponAM InterestAccruedBM InterestAccruedAM CreditSpreadBM CreditSpreadAM FlexStatus_n=="No Flex" FlexStatus_n=="Flexed Up" FlexStatus_n=="Flexed Down" CallProvision_n="No Call" CallProvision_n="Soft Call" CallProvision_n="Hard Call" InterestFrequency_n=="MONTHLY" InterestFrequency_n=="QUARTERLY" Guaranteed_n=="No" Guaranteed_n=="Yes" SponsorLed_n=="No" SponsorLed_n=="Yes" Amended_n=="No" Amended_n=="Yes" OriginalIssueDiscountSecurity_n=="No" OriginalIssueDiscountSecurity_n=="Yes"
    I also want the summary to cover mean, median, standard deviation and number of observations. The traditional
    Code:
    sum
    does not seem to include median, is there an option somewhere to change this? Some guidance for both these issues would be much appreciated.

    Thank you in advance,
    Caleb

  • #2
    Caleb:
    do you mean something along the following lines?
    Code:
    use "https://www.stata-press.com/data/r16/nlswork.dta"
    
    . bysort union: tabstat tenure, stat(count mean sd p50 min max)
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> union = 0
    
        variable |         N      mean        sd       p50       min       max
    -------------+------------------------------------------------------------
          tenure |     14539  3.602758  3.872048      2.25         0     24.75
    --------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> union = 1
    
        variable |         N      mean        sd       p50       min       max
    -------------+------------------------------------------------------------
          tenure |      4471  5.160982  4.661994  3.583333         0  25.91667
    --------------------------------------------------------------------------
    
    ---------------------------------------------------------------------------------------------------------------------------------------
    -> union = .
    
        variable |         N      mean        sd       p50       min       max
    -------------+------------------------------------------------------------
          tenure |      9091   1.35603  1.817795       .75         0      20.5
    --------------------------------------------------------------------------
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Hi Carlo,

      Thank you, the above code you have given does in fact work well. However, I want to export the data to Microsoft Word and using the following code;

      Code:
      bysort BICSLevel1_n: tabstat AmtRecovered, stat(mean sd count)
      outreg2 using myreg.doc, replace ctitle(Model 1)
      I receive this error message - matrix e(b) not found; run/post a regression, or specify varlist for non-regression outputs

      Any advice as to what to do from here?

      Kind regards,
      Caleb

      Comment


      • #4
        Try - putdocx - instead.
        Best regards,

        Marcos

        Comment


        • #5
          Hi Marcos,

          I tried - putdocx - but I am still getting no success. For clarification, where should it come in the code?

          Thanks,
          Caleb

          Comment


          • #6
            Maybe this text of the Stata Manual will be helpful.
            Best regards,

            Marcos

            Comment

            Working...
            X