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

From |
Matthew Weinberg <mweinber@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: basic mata structure question |

Date |
Mon, 17 Sep 2007 17:09:04 -0400 |

Got it. Thanks Ben.--Matt Ben Jann wrote:

Matthew, what you get back is the address of the created struct. In

oder to use the returned structure, you have to declare it beforehand

(note that you cannot use structures in interactive mode). You could

code something like the following:

function whatever()

{

struct mups scalar ms

...

ms = markups(s,p,b)

... ms.margins ...

... ms.marks ...

...

}

ben

On 9/17/07, Matthew Weinberg <mweinber@terry.uga.edu> wrote:

I'm trying to use structures for the first time and am having a little*

trouble.

I want the function markups to take three arguments (s,p,b) and return

three arguments (margins, marks, and costs). I'm getting back one

My code is:

mata

struct mups{ /*define the structure*/

real matrix margins

real matrix marks

real matrix costs

}

struct mups function markups(s,p,b) /*define the function*/

{

struct mups scalar ms /*declare structure variable*/

n=rows(s)

S=J(n,n,0)

for(i=1;i<=n;i++){

for(j=1;j<=n;j++){

S[i,j]=-b*s[i]*s[j]

}

}

for(i=1;i<=n;i++){

S[i,i]=-b*s[i]*s[i]+b*s[i]

}

Omega=I(n)*S

ms.margins=invsym(Omega)*s

ms.costs=p-ms.margins

ms.marks=(p-ms.costs):/p

return(ms)

}

end

When I evaluate my function, I get back what something like 0x27c65c

instead of the three vectors margins, costs, and marks. I'd really

appreciate it if somebody could tell me what I'm doing wrong. Thanks, Matt

*

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

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

**References**:**st: basic mata structure question***From:*Matthew Weinberg <mweinber@terry.uga.edu>

**Re: st: basic mata structure question***From:*"Ben Jann" <ben.jann@gmail.com>

- Prev by Date:
**Re: st: basic mata structure question** - Next by Date:
**st: too many files for dirlist** - Previous by thread:
**Re: st: basic mata structure question** - Next by thread:
**st: basic quesion about using structures in mata** - Index(es):

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