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

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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Re: Extracting specific elements from a matrix |

Date |
Mon, 5 Jul 2010 23:16:31 +0200 |

<> Vectors are not really part of Stata parlance, I am afraid, which may well be a shock for those who previously used other products. When you say -generate-, you create a new column of data. If you want only the first ten rows to be filled with data, as for the "y" variable in the example, you can do that, but the rest (11 to _N) must contain something, they cannot just be blank, as in some spreadsheet software products. *** clear* set obs 15 gen byte x=_n gen byte y=_n in 1/10 l *** You may also want to look at the -el()- function, btw. HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Dani Tilley Sent: Montag, 5. Juli 2010 23:10 To: statalist@hsphsun2.harvard.edu Subject: st: Re: Extracting specific elements from a matrix Much appreciated Martin. Incidentally, how do you go about creating an empty vector in Stata? I noticed that -generate- creates a new variable of length N,but what if I want a variable of length 10? I tried macro and local but they appear to hold strings rather than floats. ----- Original Message ---- <> Either talk to the coeff as "_b" (-help _variables-) or define a -matrix- and extract from it: *********** sysuse auto, clear reg price weight length rep78 di _b[weight] mat A=e(b) di A[1,1] *********** HTH Martin From: Dani Tilley <tilleydani@yahoo.com> To: statalist@hsphsun2.harvard.edu Sent: Mon, July 5, 2010 4:36:25 PM Subject: Extracting specific elements from a matrix Hi, I need to extract the first element of a matrix of coefficients and store it on a variable, and repeat the process i times. I can set up the for loop and do the storing, but I don't know how to access element [i,j] of a matrix A. In particular, my matrix is e(b), the vector of coefficients from a regression with k explanatory variables. I tried -e(b)[1,1]- but that didn't take me far. Any help is appreciated. Thanks, DF Tilley * * 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/

**References**:**st: Re: Extracting specific elements from a matrix***From:*Dani Tilley <tilleydani@yahoo.com>

- Prev by Date:
**st: Re: Extracting specific elements from a matrix** - Next by Date:
**RE: st: mata moptimize with Nelder-Mead option: why does it care about Hessian?** - Previous by thread:
**st: Re: Extracting specific elements from a matrix** - Next by thread:
**st: Re: Extracting specific elements from a matrix** - Index(es):