Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Problem when passing factor variables to mata


From   Georges Casamatta <[email protected]>
To   "[email protected]" <[email protected]>
Subject   st: Problem when passing factor variables to mata
Date   Thu, 18 Jul 2013 18:20:09 +0000

Hi everyone, 

I have created a mata function linreg_predict3(string scalar v, string scalar c) that I call from a stata do-file. It accepts as arguments a list of variables and a vector of coefficients. When I pass two different list of variables that are supposed to be equivalent, I obtain (slightly) different results. These lists are  

L.x1a  L.x1b  L.x1c  L.x1e  L.x2a  L.x3a  L.x4a  L.x4c  L.x4d  L.x5b  L.x5d  L.x5e  L.x7a  L.x7c  L.x7d  L.x8d  L.x8e  L.x9d  2L.dum1  2L.dum2  2L.dum3  3L.cat1  4L.cat1 

and 

L_x1a  L_x1b  L_x1c  L_x1e  L_x2a  L_x3a  L_x4a  L_x4c  L_x4d  L_x5b  L_x5d  L_x5e  L_x7a  L_x7c  L_x7d  L_x8d  L_x8e  L_x9d  L_dum1_2  L_dum2_2  L_dum3_2  L_cat1_3  L_cat1_4 


The variables from the second lists are identical to the ones is the first list. For example L_x1a is created as follows:  gen L_x1a = L.x1a.

After doing M = st_data(., v) in linreg_predict3(), I get slightly different matrices in the two cases.  I looked at a particular line of M and I obtained the same values in both cases except for a single column that takes the value 0 in the first case (it corresponds to variable 3L.cat1) and 1 in the second (variable L_cat1_3), the true value being 1. I suspect a problem when passing factor variables to mata through the use of st_data().  


Thanks in advance for your help!


Georges 



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index