Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • Berit Rohde
    Guest
    Post count: 118

    Hello!
    I would like to create a table that shows the effect of only one explanatory variable on several outcome variables in different models.
    Unfortunately, wide does not allow the keep option and I can´t figure out how to combine wide and nest.
    I will give an example:

     ssc install asdoc, replace
    sysuse auto, clear
    
    *I am only interested in the effect of one explanatory variable (mpg) //
    9on two outcome variables (price and trunk) in two different models (with and without headroom)
    
     Effect of mpg |      in Model 1     in Model 2  
    ---------------+---------------------------------
          on price |          ?        	   ? 
          on trunk |          ?        	   ?
    
    Suggestion on how to combine: 
    
    asdoc reg price mpg rep78 , nest replace keep(mpg)
    asdoc reg price mpg rep78 headroom, nest keep(mpg)
    
    asdoc reg trunk mpg rep78, wide keep(mpg)
    asdoc reg trunk mpg rep78 headroom, wide keep(mpg) 

    I really hope, somebody can help me out!

    Attaullah Shah
    Keymaster
    Post count: 69

    This is not possible using the wide and nest options together. However, such customized tables can be easily made with the new asdocx. Here is the code to be used with asdocx

    
    *Add the first header row
    asdocx addrow, data(Effect of mpg, in Model 1, in Model2) col(1) row(1)
    
    *The Regressions
    reg price mpg rep78
    loc mpg1 = _b[mpg]
    reg price mpg rep78 headroom
    loc mpg2 = _b[mpg]
    
    *Now write the complete row
    asdocx addrow, data(on price, `mpg1' , `mpg2') col(1) row(2) dec(3)
    
    *Another set of regressions
    reg trunk mpg rep78
    loc mpg1 = _b[mpg]
    reg trunk mpg rep78 headroom
    loc mpg2 = _b[mpg]
    
    *Write another row
    asdocx addrow, data(on trunk,  `mpg1' , `mpg2') col(1) row(3) dec(3)
    
    *And then export to Word
    asdocx export
    It  produces the following output
    
    ----+---------------------------------------------
      1 |Effect of mpg         in Model 1   in Model2 
    ----+---------------------------------------------
      2 |on price                -271.643    -289.346 
      3 |on trunk                  -0.456      -0.303 
    --------------------------------------------------
    
    

    Moreover, if this is something you need frequently, you easily create a template file with the above code and use it with asdocx.

    Berit Rohde
    Guest
    Post count: 118

    Thanks for your quick answer! It is for sure very useful.
    Thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.