Notice: On March 31, it was **announced** that Statalist is moving from an email list to a **forum**. The old list will shut down on April 23, and its replacement, **statalist.org** is already up and running.

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

From |
<Jean-Francois.Bertrand@fin.gc.ca> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: Need help on using external global in st_view to avoid recompiling in Mata |

Date |
Fri, 30 Mar 2012 11:32:06 -0400 |

Hello all, I have written a Mata function to use with -moptimize- or -ml- to estimate a discrete labour supply model. The simplified example below works for data where I would have 3 distinct hours choice (e.g. 0 hours, 20 hours and 40 hours) with income for each choice. ---- version 11.2 mata: function LSmodel_d0(transmorphic scalar M, real scalar todo, real rowvector b, real scalar lnf, real rowvector g, real matrix H) { real colvector beta_y, beta_h real colvector U real colvector sum_eU real colvector y_chosen real colvector h_chosen real colvector L_1 real matrix y_i real matrix h_i beta_y = moptimize_util_xb(M,b,1) beta_h = moptimize_util_xb(M,b,2) st_view(y=.,.,"y_chosen") st_view(h=.,.,"h_chosen") st_view(y_i=.,.,("y0","y20","y40")) st_view(h_i=.,.,("h0","h20","h40")) U = beta_y:*y_chosen :+ beta_h:*h_chosen U_i = beta_y:*y_i :+ beta_h:*h_i sum_eU = quadrowsum(exp(U_i)) L_1 = (U :- ln(sum_eU)) lnf = moptimize_util_sum(M,L_1) } mata mosave mata_LS_singles_quad_d2(), dir(PERSONAL) replace end ---- Since I might use different hours choices for different group of the population (as done in the economic literature), I would like to avoid having to recompile the code if I want to run my estimator on, for example, 5 distinct hours choice (e.g. 0 hours, 10 hours, 20 hours, 30 hours and 40 hours) so that: st_view(y_i=.,.,("y0","y10","y20","y30","y40")) st_view(h_i=.,.,("h0","h10","h20","h30","h40")) I was thinking of defining a global macro that could vary depending on the data I use. For example, I could use: global h_i = `""h0","h20","h40""' or global h_i = `""h0","h10","h20","h30","h40""' depending on the data used. Is it possible? My attempts to use pointers and global macro (-findexternal()- or -valofexternal()-) have not worked so far. Regards, Jean-François Bertrand * * 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/

**Follow-Ups**:**Re: st: Need help on using external global in st_view to avoid recompiling in Mata***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**re: st: bX** - Next by Date:
**Re: st: Need help on using external global in st_view to avoid recompiling in Mata** - Previous by thread:
**st: gpscore for multiple treatments** - Next by thread:
**Re: st: Need help on using external global in st_view to avoid recompiling in Mata** - Index(es):