Announcement

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

  • Exporting marginal means results after conjoint command into table in word

    Dear all,

    I've been using the conjoint command to estimate marginal means (MMs) on my conjoint data and created graphs as id neatly explained in the documentation of conjoint.
    In a next step, I want to export the results into a table for publication in word. Usually, I would use estout to report regression results. This does not work here. The only command that works is asdoc. However, most of the asdoc options do not seem to work and the final table is messy.

    Ideally, I would like to end up with a table with four columns, reporting MMs of four different subgroup estimations, with SE in parentheses and p-values reported as * p<0.001, p<0.01, * p<0.05.

    Can anyone help me out with this?
    Thank you in advance, Katharina


    Code:
    ** Forced Choice Outcome
    * women
    conjoint choice values appl train equota wquota if female == 1 , est(mm) id(id) 
    matrix female_fc = e(results)
    
    * men
    conjoint choice values appl train equota wquota if female != 1 , est(mm) id(id) 
    matrix male_fc = e(results)
    
    ** Rating Outcome 
    * women
    conjoint support_1 values appl train equota wquota if female == 1 , est(mm) id(id) 
    matrix female_r = e(results)
    
    * men
    conjoint support_1 values appl train equota wquota if female != 1 , est(mm) id(id)
    matrix male_r = e(results)
    
    // results stored in matrices for creating graphs

  • #2
    Can you post some data examples using -dataex- ? See FAQ on how to use -dataex-. Not everyone, I suppose, will be familiar with the -conjoint- here (I am not). But looking at your codes, I assume that you can obtain the e(results) matrix in a separate 'k' matrix with command: - mat k = e(results) - and then write a loop to obtain the desired values from the -k matrix-.
    Roman

    Comment


    • #3
      Dear Roman, absolutely, thank you for pointing that out.

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float choice double(values appl train equota wquota) float(female id)
      0 1 3 2 1 2 0 1
      1 2 3 2 1 1 0 1
      0 1 1 2 3 1 0 1
      1 1 2 1 2 1 0 1
      0 2 2 1 1 3 0 1
      1 2 3 2 1 3 0 1
      0 1 2 2 3 3 0 1
      1 2 1 1 2 3 0 1
      1 2 1 1 2 2 0 1
      0 1 3 1 2 3 0 1
      0 1 2 2 3 2 0 1
      1 2 3 1 2 3 0 1
      0 2 2 1 3 3 0 1
      1 2 1 1 1 3 0 1
      1 1 3 1 2 1 0 1
      0 1 1 1 3 2 0 1
      1 2 2 2 1 1 0 1
      0 1 2 2 1 1 0 1
      0 1 3 1 2 3 0 1
      1 1 2 1 2 2 0 1
      1 1 1 1 1 2 0 1
      0 2 2 2 3 2 0 1
      0 1 2 1 3 1 0 1
      1 1 3 1 2 3 0 1
      1 2 3 2 2 1 0 1
      0 2 1 2 3 3 0 1
      0 2 2 2 3 2 0 1
      1 1 3 1 1 2 0 1
      1 2 1 1 2 3 0 1
      0 1 1 2 3 3 0 1
      0 1 2 1 3 3 0 1
      1 1 2 2 1 1 0 1
      end
      label values values values
      label def values 1 "diversity", modify
      label def values 2 "performance", modify
      label values appl formalization
      label def formalization 1 "unstandardized", modify
      label def formalization 2 "standardized", modify
      label def formalization 3 "anonymous", modify
      label values train training
      label def training 1 "diversity training", modify
      label def training 2 "hiring training", modify
      label values equota quotas
      label values wquota quotas
      label def quotas 1 "none", modify
      label def quotas 2 "tiebreaker", modify
      label def quotas 3 "strict quota", modify
      label values female female
      label def female 0 "male", modify

      Comment


      • #4
        I am sorry, I am not being able to run your commands posted in #1 with the data example you posted in #3. Make sure your commands work with the data example you provide. As I mentioned before that I do not know or ever used 'conjoint'; it is not an official Stata command and I don't have time to look further why the commands are not running. One reason definitiely is not having enough variation in the data example provided. See below:

        Code:
        conjoint choice values appl train equota wquota if female == 1 , est(mm) id(id)
        no observations
        r(2000);
        
        end of do-file
        
        r(2000);
        
        
        conjoint choice values appl train equota wquota if female != 1 , est(mm) id(id)
        .\ not found
        r(111);
        
        end of do-file
        
        r(111);
        
        
        . conjoint support_1 values appl train equota wquota if female == 1 , est(mm) id(id)
        variable support_1 not found
        r(111);
        
        end of do-file
        
        r(111);
        
        
        . conjoint support_1 values appl train equota wquota if female != 1 , est(mm) id(id)
        variable support_1 not found
        r(111);
        Roman

        Comment


        • #5
          You can do this to show the structure of the matrices created by this command:

          Code:
          ** Forced Choice Outcome
          * women
          conjoint choice values appl train equota wquota if female == 1 , est(mm) id(id)
          matrix f = e(results)
          clear
          svmat f, names(matcol)
          dataex in 1/20
          Copy and paste the dataex output.

          Comment


          • #6
            Katharina,

            I wanted to take a look (although I am not familiar with conjoint at all). As Roman mentioned: The dataset is not sufficient, there are no "female" cases, variable support_1 is missing. Maybe you can fix this?

            I modified the data and created an example for the first 2 models.

            Code:
            * Example generated by -dataex-. For more info, type help dataex
            collect clear
            clear
            input float choice double(values appl train equota wquota) float(female id)
            0 1 3 2 1 2 1 1
            1 2 3 2 1 1 0 1
            0 1 1 2 3 1 0 1
            1 1 2 1 2 1 0 1
            0 2 2 1 1 3 1 1
            1 2 3 2 1 3 0 1
            0 1 2 2 3 3 0 1
            1 2 1 1 2 3 0 1
            1 2 1 1 2 2 0 1
            0 1 3 1 2 3 0 1
            0 1 2 2 3 2 0 1
            1 2 3 1 2 3 0 1
            0 2 2 1 3 3 0 1
            1 2 1 1 1 3 0 1
            1 1 3 1 2 1 1 1
            0 1 1 1 3 2 0 1
            1 2 2 2 1 1 0 1
            0 1 2 2 1 1 0 1
            0 1 3 1 2 3 0 1
            1 1 2 1 2 2 0 1
            1 1 1 1 1 2 0 1
            0 2 2 2 3 2 0 1
            0 1 2 1 3 1 0 1
            1 1 3 1 2 3 0 1
            1 2 3 2 2 1 0 1
            0 2 1 2 3 3 1 1
            0 2 2 2 3 2 0 1
            1 1 3 1 1 2 0 1
            1 2 1 1 2 3 0 1
            0 1 1 2 3 3 0 1
            0 1 2 1 3 3 0 1
            1 1 2 2 1 1 0 1
            
            1 1 3 2 1 2 1 0
            0 2 3 2 1 1 0 0
            0 1 1 2 3 1 0 0
            1 1 2 1 2 1 0 0
            1 2 2 1 1 3 1 0
            1 2 3 2 1 3 0 0
            1 1 2 2 3 3 0 0
            1 2 1 1 2 3 0 0
            1 2 1 1 2 2 0 0
            0 1 3 1 2 3 0 0
            1 1 2 2 3 2 0 0
            1 2 3 1 2 3 0 0
            1 2 2 1 3 3 0 0
            1 2 1 1 1 3 0 1
            1 1 3 1 2 1 1 1
            0 1 1 1 3 2 0 1
            1 2 2 2 1 1 0 1
            0 1 2 2 1 1 0 1
            0 1 3 1 2 3 0 1
            1 1 2 1 2 2 0 1
            1 1 1 1 1 2 0 1
            0 2 2 2 3 2 0 1
            0 1 2 1 3 1 0 1
            1 1 3 1 2 3 0 1
            1 2 3 2 2 1 0 1
            0 2 1 2 3 3 1 1
            0 2 2 2 3 2 0 1
            1 1 3 1 1 2 0 1
            1 2 1 1 2 3 0 1
            0 1 1 2 3 3 0 1
            0 1 2 1 3 3 0 1
            1 1 2 2 1 1 0 1
            
            end
            label values values values
            label def values 1 "diversity", modify
            label def values 2 "performance", modify
            label values appl formalization
            label def formalization 1 "unstandardized", modify
            label def formalization 2 "standardized", modify
            label def formalization 3 "anonymous", modify
            label values train training
            label def training 1 "diversity training", modify
            label def training 2 "hiring training", modify
            label values equota quotas
            label values wquota quotas
            label def quotas 1 "none", modify
            label def quotas 2 "tiebreaker", modify
            label def quotas 3 "strict quota", modify
            label values female female
            label def female 0 "male", modify
            label def female 1 "female", modify

            Unfortunately I cannot figure out how to include/attach the significance stars. But maybe the example is helpful anyways and somebody else has an idea?!

            Code:
            collect clear
            
            * women
            collect: conjoint choice values if female == 1 , est(mm) id(id)
            matrix female_fc = e(results)
            
            * men
            collect: conjoint choice values appl train if female != 1 , est(mm) id(id)
            matrix male_fc = e(results)
            
            collect remap colname["P>|t|"] = colname[p]
            
            collect style cell colname[SE], sformat((%s))
            collect style cell colname[SE], nformat(%4.3f)
            collect style cell colname[p], nformat(%4.2f)
            
            *collect stars p 0.01 "***" 0.05 "**" 0.9 "*"        // not working
            *collect remap result[stars] = colname[stars]
            
            collect layout (rowname[diversity]#colname[Est.]#colname[SE]#colname[p] rowname[performance]#colname[Est.]#colname[SE]#colname[p]) (cmdset)

            Code:
            -----------------------------
                        |       1       2
            ------------+----------------
            diversity   |                
              Est.      |     .75   .4375
              SE        | (0.135) (0.051)
              p         |    0.32    0.44
            performance |                
              Est.      |     .25     .75
              SE        | (0.405) (0.042)
              p         |    0.65    0.11
            -----------------------------

            Comment


            • #7
              Based on Simon's data above, here is mine that will export the results in excel with significance. But, I am sure people here will write more efficient codes than mine:

              Code:
              
              lab var choice "Choice" //labelling the 'choice' variable
              
              putexcel set test.xlsx, sheet(test) modify
              
              loc row = 4
              
              foreach v of varlist choice { //add your other variables here
                  
                  forval i = 0/1 {
                      loc gender_lab : lab female `i'
                
                      conjoint `v' values if female == `i', est(mm) id(id)
                      matrix k = e(results)
              
                      loc rownames : rownames k
                      loc wc : word count `rownames'
                      
                      forval j = 1/`wc' {
                          
                          loc rowlab : word `j' of `rownames'
                          loc b     : di %3.2f k[`j', 1]
                          loc se     : di %3.2f k[`j', 2]
                          loc p    : di %4.3f k[`j', 4]
                      
                          if `p' <= .001 {
                              loc sig = "***"
                          }
                          else if `p' <= .01 {
                              loc sig = "**"
                          }
                          else if `p' <= .05 {
                              loc sig = "*"
                          }
                          else  {
                              loc sig = ""
                          }
                          
                          putexcel A`row' = "`:var lab `v''"
                          putexcel B`row' = "`gender_lab'"
                          putexcel C`row' = "`rowlab'"
                          putexcel D`row' = "`b' (`se')`sig'"
                          
                          loc ++row
                      }
                  }
              }
              Roman

              Comment


              • #8
                Originally posted by Katharina Stuckradt View Post
                Dear Roman, absolutely, thank you for pointing that out.

                Code:
                * Example generated by -dataex-. For more info, type help dataex
                clear
                input float choice double(values appl train equota wquota) float(female id)
                0 1 3 2 1 2 0 1
                1 2 3 2 1 1 0 1
                0 1 1 2 3 1 0 1
                1 1 2 1 2 1 0 1
                0 2 2 1 1 3 0 1
                1 2 3 2 1 3 0 1
                0 1 2 2 3 3 0 1
                1 2 1 1 2 3 0 1
                1 2 1 1 2 2 0 1
                0 1 3 1 2 3 0 1
                0 1 2 2 3 2 0 1
                1 2 3 1 2 3 0 1
                0 2 2 1 3 3 0 1
                1 2 1 1 1 3 0 1
                1 1 3 1 2 1 0 1
                0 1 1 1 3 2 0 1
                1 2 2 2 1 1 0 1
                0 1 2 2 1 1 0 1
                0 1 3 1 2 3 0 1
                1 1 2 1 2 2 0 1
                1 1 1 1 1 2 0 1
                0 2 2 2 3 2 0 1
                0 1 2 1 3 1 0 1
                1 1 3 1 2 3 0 1
                1 2 3 2 2 1 0 1
                0 2 1 2 3 3 0 1
                0 2 2 2 3 2 0 1
                1 1 3 1 1 2 0 1
                1 2 1 1 2 3 0 1
                0 1 1 2 3 3 0 1
                0 1 2 1 3 3 0 1
                1 1 2 2 1 1 0 1
                0 2 1 1 1 3 1 2
                1 1 2 2 3 1 1 2
                0 1 1 2 3 2 1 2
                1 1 1 1 1 2 1 2
                0 2 1 1 2 2 1 2
                1 2 1 1 1 1 1 2
                0 1 2 1 2 1 1 2
                1 2 1 2 3 3 1 2
                0 1 3 1 2 2 1 2
                1 1 3 2 2 2 1 2
                0 1 3 1 3 1 1 2
                1 2 1 1 3 3 1 2
                0 1 1 1 2 1 1 2
                1 2 2 1 1 1 1 2
                0 2 3 1 3 3 1 2
                1 2 2 1 2 1 1 2
                0 1 1 1 2 1 1 2
                1 1 1 1 1 1 1 2
                1 2 2 2 1 2 1 2
                0 1 1 1 3 2 1 2
                0 2 1 1 2 3 1 2
                1 2 3 1 1 3 1 2
                1 2 1 1 1 2 1 2
                0 1 2 1 2 1 1 2
                0 2 3 1 1 2 1 2
                1 1 2 2 3 1 1 2
                1 2 1 1 3 1 1 2
                0 2 3 1 3 3 1 2
                0 1 2 1 2 3 1 2
                1 1 2 2 2 3 1 2
                0 1 3 1 3 1 1 2
                1 2 1 2 2 1 1 2
                0 2 1 2 2 3 0 3
                1 2 1 2 2 2 0 3
                1 1 1 1 2 1 0 3
                0 2 3 2 3 3 0 3
                0 1 3 2 2 3 0 3
                1 2 3 1 2 2 0 3
                1 2 3 1 2 1 0 3
                0 1 1 2 3 2 0 3
                0 2 1 2 1 1 0 3
                1 2 1 2 1 3 0 3
                1 1 3 1 1 2 0 3
                0 1 1 1 2 1 0 3
                0 2 2 2 3 1 0 3
                1 2 3 1 2 1 0 3
                1 2 3 1 1 1 0 3
                0 2 1 2 1 2 0 3
                0 2 2 1 3 1 0 3
                1 2 3 1 1 3 0 3
                0 2 2 1 1 3 0 3
                1 2 3 1 1 2 0 3
                0 2 3 2 3 3 0 3
                1 1 1 1 2 1 0 3
                1 2 1 2 2 1 0 3
                0 1 2 2 1 1 0 3
                0 2 2 2 2 3 0 3
                1 2 1 2 3 3 0 3
                0 2 3 2 3 1 0 3
                1 1 3 2 3 1 0 3
                1 1 3 2 2 2 0 3
                0 2 3 2 2 3 0 3
                1 1 3 2 3 1 0 3
                0 2 3 2 1 3 0 3
                0 1 1 1 3 1 1 4
                1 2 1 1 3 1 1 4
                1 2 2 1 2 2 1 4
                0 2 2 2 1 3 1 4
                1 2 2 2 2 3 1 4
                0 2 2 1 3 3 1 4
                0 1 2 2 3 3 1 4
                1 2 1 2 3 2 1 4
                1 2 1 1 1 2 1 4
                0 2 2 1 3 2 1 4
                0 1 2 2 3 1 1 4
                1 2 2 1 3 3 1 4
                1 1 3 1 2 1 1 4
                0 1 3 2 3 1 1 4
                0 2 3 1 3 1 1 4
                1 1 2 2 2 3 1 4
                0 1 2 1 1 1 1 4
                1 2 2 2 1 2 1 4
                1 1 1 1 3 1 1 4
                0 2 3 1 3 2 1 4
                0 1 2 2 2 3 1 4
                1 2 1 2 3 1 1 4
                0 1 2 2 3 2 1 4
                1 1 1 2 2 3 1 4
                0 1 2 1 1 1 1 4
                1 2 2 2 2 2 1 4
                1 2 1 1 3 1 1 4
                0 1 3 1 2 3 1 4
                0 1 1 2 3 3 1 4
                1 2 1 2 3 3 1 4
                1 1 1 1 2 1 1 4
                0 2 2 2 1 3 1 4
                1 2 1 2 2 3 0 5
                0 1 3 2 3 1 0 5
                0 1 1 2 3 3 0 5
                1 1 1 2 2 1 0 5
                0 1 3 2 2 2 0 5
                1 2 2 1 1 2 0 5
                0 1 3 1 1 1 0 5
                1 2 2 2 3 1 0 5
                0 2 2 1 3 3 0 5
                1 2 2 1 1 2 0 5
                1 2 1 2 2 2 0 5
                0 2 1 2 2 3 0 5
                0 2 1 2 3 2 0 5
                1 2 1 2 1 1 0 5
                1 2 2 2 2 2 0 5
                0 1 3 1 1 3 0 5
                0 1 2 1 1 3 0 5
                1 2 2 1 3 2 0 5
                1 2 3 2 3 1 0 5
                0 1 3 2 1 3 0 5
                0 1 2 2 3 1 0 5
                1 2 2 2 1 1 0 5
                1 2 3 2 1 1 0 5
                0 2 1 2 3 1 0 5
                1 1 1 2 1 1 0 5
                0 1 2 1 1 3 0 5
                0 1 1 2 3 2 0 5
                1 1 2 2 2 1 0 5
                0 1 1 2 2 3 0 5
                1 1 1 2 1 2 0 5
                0 1 1 1 1 1 0 5
                1 2 3 1 2 2 0 5
                end
                label values values values
                label def values 1 "diversity", modify
                label def values 2 "performance", modify
                label values appl formalization
                label def formalization 1 "unstandardized", modify
                label def formalization 2 "standardized", modify
                label def formalization 3 "anonymous", modify
                label values train training
                label def training 1 "diversity training", modify
                label def training 2 "hiring training", modify
                label values equota quotas
                label values wquota quotas
                label def quotas 1 "none", modify
                label def quotas 2 "tiebreaker", modify
                label def quotas 3 "strict quota", modify
                label values female female
                label def female 0 "male", modify
                label def female 1 "female", modify

                Apologies, I included a larger number of cases in the example data. The command I provided above does now work with the example data.

                Comment


                • #9
                  Thank you both very much, Roman and Simon. Let me dive into both of your approaches and see with which one I can go further.

                  Comment

                  Working...
                  X