Statalist


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

Re: st: matrix question


From   Tirthankar Chakravarty <[email protected]>
To   [email protected]
Subject   Re: st: matrix question
Date   Sat, 8 Aug 2009 17:27:23 +0100

<>

Does this work? The example is a little facetious, as all the
variables are always positive.
****************************
clear*
cap  prog drop bif_des
program bif_des
	cap drop _*
	quietly des,varlist
	tokenize `r(varlist)'
	local first `1'
	macro shift
	local rest `*'
	local t: word count `rest'
	local colnames
	tokenize `rest'
	forval o=2(2)`t' {
	       local colnames `colnames' ``o''
	       gen _``o''pos=1 if (``o''>0 & ``o''!=.)
	       replace _``o''pos=0 if (``o''<0)
	       estpost tab _``o''pos, mi
	       matrix def o=e(pct)
	       matrix def l=e(cumpct)
	       mat A=(nullmat(A),(o[1,1..2],l[1,2])')
	       }
	mat colnames A = `colnames'
	mat list A
end
sysuse auto, clear
bif_des
****************************

T

On Sat, Aug 8, 2009 at 4:59 PM, moleps islon<[email protected]> wrote:
> That is exactly what I'm looking for, however applying your code to my
> program doesnt work ( though your code works beautifully). I end up
> with r503 conformability error. And also instead of a [8,4] matrix I
> get a [1,24] matrix.
>
> Moleps
>
>
> capture  program drop  bif_des
> program bif_des
> capture drop _*
> quietly des,varlist
>
> local r `r(varlist)'
> di "`r'"
> tokenize `r'
> local first `1'
> macro shift
> local rest `*'
>
> local t:word count `rest'
>
> tokenize `rest'
> forval o=2(2)`t' {
>
>       local rowname `rowname' ``o''
>       gen _``o''pos=1 if (``o''>0 & ``o''<.)
>       replace _``o''pos=0 if (``o''<0)
>       estpost tab _``o''pos,mi
>       matrix def o=e(pct)
>       matrix def l=e(cumpct)
>       mat A=(nullmat(A),(o[1,1..2],l[1,2])')
>       mat list A
>       }
> mat rownames A = `rowname'
>
> end
> *
> *   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/
>



-- 
To every ω-consistent recursive class κ of formulae there correspond
recursive class signs r, such that neither v Gen r nor Neg(v Gen r)
belongs to Flg(κ) (where v is the free variable of r).

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



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