Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: mata st_view( ) and change in stata data


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: mata st_view( ) and change in stata data
Date   Thu, 30 Nov 2006 16:24:28 -0000

The Mata issue aside, this is just to underline that this 
is something that can also be done quite easily in Stata. 

egen rowmax = rowmax(<varlist>) 

foreach v of var <varlist> { 
	// replace `v' = `v' / rowmax 
	// generate `v'scaled = `v' / rowmax 
} 

where you remove which comment indicator you need
to do what you want. 

Naturally, you could write much faster code using Mata 
to do what you want, but there is still a matter of 
convenience. 

Nick 
[email protected] 

Carl Nelson
 
> The mata manual explains
> 
> st_view(X, ., ("mpg", "displ", "weight"))
> X[2,1] = 123
> 
> will cause the second observation of mpg in stata to change.
> 
> I am trying to use mata to divide each row of 54 variables by 
> their row
> maximums. The mata code is
> 
> mata
> st_view(a, .,(" over04"," over05"," expect04"," expect05"," 
> repeat04"," repeat05"," othover04"," othover05"," clean04"," 
> clean05"," meatqaul04"," meatqual05"," meatvar04"," meatvar05"," 
> vegqual04"," vegqual05"," vegvar04"," vegvar05"," deliqual04"," 
> deliqual05"," delivar04"," delivar05"," bakequal04"," bakequal05"," 
> bakevar04"," bakevar05"," grocvar04"," grocvar05"," stock04"," 
> stock05"," nature04"," nature05"," help04"," help05"," checkout04"," 
> checkout05"," specserv04"," specserv05"," community04"," 
> community05"," prices04"," prices05"," discount04"," discount05"," 
> special04"," special05"," specsotck04"," specstock05"," 
> loyalprice04"," loyalprice05"," loyalstock04"," loyalstock05"," 
> location04"," location05"))
> t = (0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\70\0\0\0\0\0\0\0\0\0\0\0\0\0)
> a = a :+ t
> r = rowscalefactors(a)
> _equilr(a,r)
> end
> 
> After I run this the matrix a in mata is correct, but the variables 
> in the stata data set haven't been
> changed.
> 
> I would appreciate any help correcting my error. Thanks.

*
*   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