Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

From |
Mirko <mirko.moro@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: extract part of matrix e(b) |

Date |
Fri, 22 Jul 2011 19:42:33 +0100 |

Hi Jorge, Thanks very much for your answer. What if I need to save matrices because I need to do other tests and calculations? Please check the example below: sysuse auto, clear set more off regress mpg foreign i.rep78##c.weight headroom margins, dydx(rep78) (output omitted) . matrix b_num = r(b) . matrix colna b_num = num: . matrix J_num = r(Jacobian) . matrix rowna J_num = num: . margins, dydx(weight) over(rep78) (output omitted) . matrix b_den = r(b) . matrix colna b_den = den: . matrix J_den = r(Jacobian) . matrix rowna J_den = den: . * combine the results . matrix b = b_num, b_den . matrix J = J_num \ J_den . matrix V = J*e(V)*J' . ereturn post b V . * check that the combined results match those from the original . ereturn display (output omitted) . nlcom (R2: [num]_b[2.r]/[den]_b[2.r]) (R3: [num]_b[3.r]/[den]_b[3.r]) (R4: [num]_b[4.r]/[den]_b[4.r]) (R5 [num]_b[5.r]/[den]_b[5.r]) However, I don't want to use the entire e(b) matrix but just part of it...Does it work if I save the coefficients as scalars, then I create a matrix? Mirko On 22 July 2011 17:32, Joerg Luedicke <joerg.luedicke@gmail.com> wrote: > You could grab it from the matrix by addressing row and column > numbers, for example: > > scalar second=b[1,2] > scalar third=b[1,3] > > J. > > > On Fri, Jul 22, 2011 at 12:03 PM, Mirko <mirko.moro@gmail.com> wrote: >> Dear Statalisters, >> >> I wish to extract only some coefficients from the matrix e(b) and I >> wonder how this can be achieved. >> >> Here is a simple example. >> >> . regress mpg foreign i.rep78##c.weight headroom >> (output omitted) >> >> . margins, dydx(rep78) >> (output omitted) >> >> . mat b =e(b) >> >> This command extracts and saves the entire coefficients matrix e(b) as b. >> >> If you type: >> >> . mat li b >> >> you get: >> >> b[1,5] >> 1b. 2. 3. 4. 5. >> rep78 rep78 rep78 rep78 rep78 >> y1 0 .25956254 -.74363551 -.38630819 -6.5437415 >> >> >> What should I do if I wish to grab only the second and third >> coefficients: .25956254, -.74363551 instead the all matrix? >> >> How this can be done? >> >> Mirko >> * >> * For searches and help try: >> * http://www.stata.com/help.cgi?search >> * http://www.stata.com/support/statalist/faq >> * http://www.ats.ucla.edu/stat/stata/ >> > > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**Follow-Ups**:**Re: st: extract part of matrix e(b)***From:*Nick Cox <njcoxstata@gmail.com>

**References**:**st: extract part of matrix e(b)***From:*Mirko <mirko.moro@gmail.com>

**Re: st: extract part of matrix e(b)***From:*Joerg Luedicke <joerg.luedicke@gmail.com>

- Prev by Date:
**Re: st: extract part of matrix e(b)** - Next by Date:
**st: BASIC QUESTION - counts of counts** - Previous by thread:
**Re: st: extract part of matrix e(b)** - Next by thread:
**Re: st: extract part of matrix e(b)** - Index(es):