I have not managed to figure out yet how to use the name of the variable to access the member of the structure.

Suppose the structure is called st1 and the string is string1 = "num".

How do I access st1.num in the function by using string1?]]>

Code:

mata real scalar function my_mean (real vector x) { return(sum(x) / (length(x) - missing(x))) } real scalar function my_quadmean (real vector x) { return(quadsum(x) / (length(x) - missing(x))) } n = 500000 x = runiform(n, 1) x[selectindex(x :< 0.1)] = J(sum(x :< 0.1), 1, missingof(x)) ixl = (1::n) :- 100 ixu = (1::n) :+ 100 ixl[selectindex(ixl :< 1)] = J(sum(ixl :< 1), 1, 1) ixu[selectindex(ixu :> n)] = J(sum(ixu :> n), 1, n) y1 = J(n, 1, .) y2 = J(n, 1, .) y3 = J(n, 1, .) end timer clear timer on 1 mata for (i = 1; i <= n; i++) { y1[i] = mean(x[|ixl[i] \ ixu[i]|]) } end timer off 1 timer on 2 mata for (i = 1; i <= n; i++) { y2[i] = my_mean(x[|ixl[i] \ ixu[i]|]) } end timer off 2 timer on 3 mata for (i = 1; i <= n; i++) { y3[i] = my_quadmean(x[|ixl[i] \ ixu[i]|]) } end timer off 3 mata assert(all(y1 :== y3))

Code:

. timer list 1: 90.75 / 1 = 90.7530 2: 4.57 / 1 = 4.5670 3: 4.85 / 1 = 4.8490

Code:

. timer list 1: 6.11 / 1 = 6.1070 2: 1.76 / 1 = 1.7610 3: 1.94 / 1 = 1.9430

I have a question regarding numerical integration in mata. My problem is something of this sort. I am trying to integrate f(x,y,z) = x+2y+2z over the range of x from 0 to 1, fixing the value of y and z. However I am struggling to implement this in mata. Here are my codes

real rowvector fxy2(real rowvector x, real rowvector y, real rowvector z)

{

return(x:+(2:*y)+(2:*z))

}

real rowvector f_inner2(real rowvector y,real rowvector z)

{

f = integrate(&fxy2(),0,1,40,(y,z))

return (f)

}

: f_inner2(3,3)

fxy2(): 3001 expected 3 arguments but received 2

integrate_main(): - function returned error

integrate(): - function returned error

f_inner2(): - function returned error

<istmt>: - function returned error

The correct solution should be 12.5, but I am not getting that. Can someone please point out where is the problem in my code and how can I fix it? Thanks. ]]>

I am new to mata and have a question related to matrix manipulation in MATA. I have:

- A = (1;2;3) 3 x 1 column vector
- B = (1,2) 1 x 2 row vector

Code:

gsem (i.binary <- IV) (y<- i.binary) (y<- x1 x2 x3), nocapslatent vce(cluster Unternehmen)]]>

BANKID | cash_bal2000Q1 | securities2000Q1 | fedfnd_revrepo2000Q1 | loan_lease_hfs2000Q1 | Joint-venture2000Q1 | other assets2000Q1 | TradingAssets2000Q1 | IntangibleAssets2000Q1 | otherrealestate2000Q1 | securities2000Q1 | fixedassets2000Q1 | net-loans2000Q1 |

100003 | 0.0523267 | 0.3282848 | 0.0035845 | 0.0051423 | 0.0035845 | 0.0523267 | 0.3282848 | 0.0035845 | 0.0051423 | 0.0035845 | 0.0523267 | 0.0035845 |

100134 | 0.023778 | 0.2791913 | 0.0038878 | 0 | 0.0038878 | 0.023778 | 0.2791913 | 0.0038878 | 0 | 0.0038878 | 0.023778 | 0.0038878 |

100135 | 0.0230704 | 0.2506895 | 0.00654 | 0.000572 | 0.00654 | 0.0230704 | 0.2506895 | 0.00654 | 0.000572 | 0.00654 | 0.0230704 | 0.00654 |

100144 | 0.1323925 | 0.0914672 | 0.0345783 | 0 | 0.0345783 | 0.1323925 | 0.0914672 | 0.0345783 | 0 | 0.0345783 | 0.1323925 | 0.0345783 |

100154 | 0.0534938 | 0.0709148 | 0.0026255 | 0.0053682 | 0.0026255 | 0.0534938 | 0.0709148 | 0.0026255 | 0.0053682 | 0.0026255 | 0.0534938 | 0.0026255 |

100161 | 0.0506434 | 0.2294578 | 0.0018176 | 0.0080809 | 0.0018176 | 0.0506434 | 0.2294578 | 0.0018176 | 0.0080809 | 0.0018176 | 0.0506434 | 0.0018176 |

100165 | 0.0256106 | 0.2885543 | 0.0335942 | 0.0220141 | 0.0335942 | 0.0256106 | 0.2885543 | 0.0335942 | 0.0220141 | 0.0335942 | 0.0256106 | 0.0335942 |

100173 | 0.0333732 | 0.2799982 | 0.0094496 | 0 | 0.0094496 | 0.0333732 | 0.2799982 | 0.0094496 | 0 | 0.0094496 | 0.0333732 | 0.0094496 |

100184 | 0.0518307 | 0.2053013 | 0.0196109 | 0.0006451 | 0.0196109 | 0.0518307 | 0.2053013 | 0.0196109 | 0.0006451 | 0.0196109 | 0.0518307 | 0.0196109 |

100185 | 0.0379655 | 0.3561531 | 0.004141 | 0.0001412 | 0.004141 | 0.0379655 | 0.3561531 | 0.004141 | 0.0001412 | 0.004141 | 0.0379655 | 0.004141 |

100196 | 0.0873589 | 0.2289798 | 0.0161368 | 0.0026473 | 0.0161368 | 0.0873589 | 0.2289798 | 0.0161368 | 0.0026473 | 0.0161368 | 0.0873589 | 0.0161368 |

For an assignment I need to write a Mata program that recognises the kind of input and either runs the function for a Mata matrix or for the Stata variable that is specified in the function.

Here you see the (simplified) program,

Code:

clear mata mata real matrix function posmean (real vector x) { real vector A, B A = select(x, x[1,.]:>0) B = mean(A') return(B) } x1 = (1, 2, -3, 4, 5, -6) x2 = (1 \ 2 \ 3 \ -4 \ 4) posmean(x1) posmean(x2) } end

Here you see the (simplified) program,

Code:

sysuse auto, clear clear mata mata: real matrix function posmean(transmorphic vector x) { real vector C, D st_view(L=.,.,x) C = select(L,L[.,.]:>0) D = mean(C) return(D) } posmean("price") end

Thank you very much in advance!

Best wishes

Anika]]>

Does anyone have an idea why this error message could be popping up? Or what does it mean?

Thanks!]]>

Thanks guys!]]>

install dataex

clear input byte Director int year float moneyness end sort Director year by ceo: generate Holder67 = sum(conf>=.67) by ceo: replace Holder67 = 0 if Holder67[_N]<2 by ceo: replace Holder67 = 1 if Holder67>1]]>

I am a novice STATA user hence kindly bare with me if my question is basic. I executed the following commands:

Code:

mhodds tb hiv2 if missing==0, by(bmigrp) c(1,0) Maximum likelihood estimate of the odds ratio Comparing hiv2==1 vs. hiv2==0 by bmigrp ------------------------------------------------------------------------------- bmigrp | Odds Ratio chi2(1) P>chi2 [95% Conf. Interval] ----------+-------------------------------------------------------------------- <19 | 8.000000 16.53 0.0000 2.42589 26.38208 19-24 | 2.311694 5.60 0.0179 1.13161 4.72239 25+ | 3.213415 3.89 0.0486 0.94169 10.96542 ------------------------------------------------------------------------------- Mantel-Haenszel estimate controlling for bmigrp ---------------------------------------------------------------- Odds Ratio chi2(1) P>chi2 [95% Conf. Interval] ---------------------------------------------------------------- 3.256096 21.22 0.0000 1.912757 5.542868 ---------------------------------------------------------------- Test of homogeneity of ORs (approx): chi2(2) = 3.22 Pr>chi2 = 0.1996

Code:

. return list scalars: r(or) = 2.796406651543788 r(lb_or) = 1.71732962901426 r(ub_or) = 4.55351729142816 r(chi2) = 18.64835958570303 r(p) = .0000157182454007 r(df_hom) = 1 r(chi2_hom) = .068043938660382

Thanks,

Paul]]>

So my questions are:

1. Could I calculate OS from HR (and the opposite)?

2. Could I calculate the C.I. 95%, if I have only OS/HR and the total of the predictors?

In order to be more clear, here is an example for the question #1:

-OS=55,3%;

-CI 95%=76,7-90,2;

-p<0,001

-n=176

(HR?).

Example for question #2:

-OS=60,6%;

-P<0,001;

-n=1920

(C.I.95%?).

Thanks for the help.

]]>

I have several questions about lud()and lusolve() functions.

Reading MATA manual relative to LU factorization - i.e., lud(numeric matrix A, L, U, p) function - I do not really get the arguments Mata is expected to receive other than the known matrix A because L and U come from LU decomposition - so, they are not yet known. Also, I do not understand how the permutation vector p is chosen. What confused me even more is the statement in the manual

I also tried to use the function _lud_la(numeric matrix A, q) setting q = (1\2\2) as documented in MATA manual. The function performs the LU decomposition smoothly but the original matrix A is modified from which L and U matrices can be extrapolated as explained in the documentation. But I do not want the original matrix A to be modified that is why I want to use lud(). So, how am I supposed to proceed?

Finally, I have a computational doubt: Is it correct that cholsolve() and lusolve() return the same solution (i.e., a vector x) when the matrix A is symmetric (and, of course, positive definite and square)? For example,

Code:

A = (2,-1\-1,2) b = J(rows(A),1,1) MatrixLUSolve = lusolve(A,b) MatrixCholSolve = cholsolve(A, b)

Thank you,

Anna]]>

Best

]]>

I am trying to solve equations to find value in STATA. Can you please have a look at the following case and give me some advices:

I have variable X (continuous variable). I would like to form a linear equation:

Y = a + b * X (1)

mean(Y) = 0 (2)

std(Y) = 1 (3)

Can I solve three equations (1), (2), and (3) to find Y, a, and b ?

Thank you very much for your time.

Nguyen.]]>