Announcement

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

  • How to get the mean for some variables by industry?

    Hello,

    I am trying to get the mean scores for my research variables and I used this command to get this by country however when I tried to get it by industry, the column for the industry didn't show the industry name instead numbers how can I see the industry name? the command I use is as follows
    Code:
     estpost tabstat VAR1 VAR2 VAR3, by(industrynamex) statistics(mean)

  • #2
    Please use dataex to include a minimal worked example.

    Comment


    • #3
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input str42 icbsubsectorname float AQ double ESGCombinedScore int CodeX
      "Transportation Services"          -.0870096                 .  474
      "Aerospace"                       -.09035578                 .  945
      "Casinos and Gambling"                     .                 .  207
      "Delivery Services"              -.026022814 .6820999999999999  377
      "Chemicals and Synthetic Fibers"  -.04178509                 .  660
      "Machinery: Industrial"           -.08162265             .5392   77
      "Sugar"                           -.04093685                 .  284
      "Restaurants and Bars"             -.1007221                 .  581
      "Machinery: Industrial"                    .                 .  407
      "Diversified Industrials"         -.05702642                 . 1240
      end

      Comment


      • #4
        The industry classification here is named (icbsubsectorname) and I am trying to calculate the mean scores for (AQ, and ESGCombinedScore) by industry

        Comment


        • #5
          Code:
          * Example generated by -dataex-. To install: ssc install dataex
          clear
          input str42 icbsubsectorname float AQ double ESGCombinedScore int CodeX
          "Transportation Services"          -.0870096                 .  474
          "Aerospace"                       -.09035578                 .  945
          "Casinos and Gambling"                     .                 .  207
          "Delivery Services"              -.026022814 .6820999999999999  377
          "Chemicals and Synthetic Fibers"  -.04178509                 .  660
          "Machinery: Industrial"           -.08162265             .5392   77
          "Sugar"                           -.04093685                 .  284
          "Restaurants and Bars"             -.1007221                 .  581
          "Machinery: Industrial"                    .                 .  407
          "Diversified Industrials"         -.05702642                 . 1240
          end
          cls
          
          cap which sencode
          
          if _rc {
              
              
              ssc inst sencode, replace
          }
          
          sencode icbsubsectorname, replace
          
          bys icbsubsectorname: eststo: qui estpost su AQ ESG, listwise mean
          
          esttab, cells("mean") label nodepvar
          Is this about what we want here?

          Comment


          • #6
            Sorry I am confused, the issue is that when I use my code it worked well by country but when I run the same code per ICBsector which is per industry, the table treats ICBsector as a numeric variable and it shows me that not the industry names,
            Code:
             
             estpost tabstat VAR1 VAR2 VAR3, by(ICBsector) statistics(mean)
            ICBsector | (AQ) VAR2 VAR3 VAR4 VAR5 VAR6 VAR7
            -------------+-----------------------------------------------------------------------------
            1 | -.0570766 .0363664 .45155 .3862337 .5709391 .5298043 .4381899
            2 | -.0648754 .4908471 .4299992 .3144265 .60511 .6370567 .5228958
            3 | -.0493442 .9997403 .201 .2107333 .1513 .1147 .3569
            4 | -.0309986 .2290099 .6949471 .5610077 .8056176 .8694353 .6694824
            5 | -.0619437 -.1906668 .5503185 .429126 .7270685 .6989891 .4633793
            6 | -.0616223 .3468806 .5236106 .3788387 .540716 .6363223 .5211553
            7 | -.0827332 .3725851 .4106636 .2190429 .5366636 .4073182 .2993182

            Comment


            • #7
              What's wrong with my code?

              Why not just do

              Code:
               qbys icbsubsectorname: eststo: qui estpost su AQ-VAR7, listwise mean
              esttab, cells("mean") label
              If I'm understanding you well, you want to see the value label.

              So if 1 is "Transportation", you want the table to show you "Transportation" for the mean of "Transportation", and not 1, right? Sally Ahmed
              Last edited by Jared Greathouse; 29 Dec 2021, 13:12.

              Comment


              • #8
                yes this is right but I tried now your code it gives me that error invalid 'cells'
                r(198);

                Comment


                • #9
                  Sally Ahmed Okay, show the exact code you used then.

                  Comment


                  • #10
                    Code:
                     
                        qbys icbsubsectorname: eststo: qui estpost su (my variables from AQ-VAR7), listwise mean  esttab, cells("mean") label

                    Comment


                    • #11
                      Sally Ahmed You need to break these up line by line. Put what I did into a do file editor. That is, your code in your do file should look like

                      Code:
                       qbys icbsubsectorname: eststo: qui estpost su (AQ-VAR7), listwise mean
                      
                      esttab, cells("mean") label

                      Your code typed exactly into the Stata terminal implies this is all one command, and it isn't.

                      Either that, or the code you've given was incomplete, since Stata should recognize the estimates from the previous estpost command stored by eststo.

                      If the error persists, show me the full context of your code, not just one line.
                      Last edited by Jared Greathouse; 29 Dec 2021, 13:11.

                      Comment

                      Working...
                      X