Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: access subsets of a matrix


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: access subsets of a matrix
Date   Wed, 27 Apr 2005 22:30:50 +0100

In the current version of Stata, there 
is a Mata solution for this. 

In Stata 8, which I guess you 
are using, I don't think there is 
an exact equivalent to the Matlab construct. 

You would need a loop, something like this: 

forval i = 1/`=rowsof(lambda)' { 
	<calculate whatever> 
	if z[`i'] == 0 lambda[`i'] = -normden(<whatever>) 
} 



Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Jens
> Hainmueller
> Sent: 27 April 2005 22:08
> To: [email protected]
> Subject: st: access subsets of a matrix
> 
> 
> Hi,
> 
> I am new to Stata programming so I have a problem to 
> translate the following
> line of mathlab code into Stata code.
> 
> lambda(z==0) = - normpdf(X(z==0,:)*gamma)
> 
> Here lambda is an (nx1) matrix, X is (nxk), gamma is (kx1), z 
> is (nx1), and
> for example X(z==0) denotes subset of the matrix X for which 
> (z==1), i.e.
> the condition in parenthesis holds true.
> 
> In Stata, how can I access this subset of my X matrix? It should be
> something like:
> 
> matrix lambda = -normde(X[if z==1]*gamma)
> 
> but I can't Stata to access the matrix subsets as I need it. 
> Thanks for your
> help.
> 
> Best,
> Jens
> 
> 
> *
> *   For searches and help try:
> *   http://www.stata.com/support/faqs/res/findit.html
> *   http://www.stata.com/support/statalist/faq
> *   http://www.ats.ucla.edu/stat/stata/
> 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index