I am trying to run a linear probability model. In the model, a dependent variable for each unique observation takes values either 0 or 1. My goal is to estimate probabilities of lying within each unique value of the dependent variable after adjusting for independent variables. My codes are as follows:
Since I am using very large data sets, I try to use MATA and then convert the matrix from MATA into STATA variables. To implement such conversion, the below codes work, but it takes very long time. Thus, I would like to know a more efficient way to convert the matrix from MATA into STATA variables. I have tried to use st_addvar and st_store, but they did not work.
Thank you in advance!
Code:
forvalues i=1/100 { use "E:\data\sample`i'.dta",clear egen group = group($y) /////////// y is a dependent variable /////////// tempname max sum group scalar `max' = r(max) forvalues a = 1(1)`=`max'' { gen y_`a' = 0 replace y_`a' = 1 if group <= `a' global group "y_*" mata: y = st_data(., "$group") mata: X = st_data(., "$xs") /////////// xs is a vector for independent variables /////////// mata: X = X, J(rows(X),1,1) mata: b = invsym(X'*X)*X'*y mata: yhat = X*b drop $group /// (continued) /// }
Code:
{ /// (continued) /// tempname max su group scalar `max' = r(max) forvalues a = 1(1)`=`max'' { mata: p_`a' = yhat[., `a'] getmata p_`a', force }
Comment