Apologies in advance for the simplicity of my question. I am sure the is already a forum answering it but I don't seem able to find it.

For the porposes of data presentation I have a square matrix, lets say M=(A,B\C,D), and I want to manipulate it so that M=(C,D\A,D).

Code:

clear matrix define M = (1,2,3\4,5,6\7,8,9) matrix list M

Many thanks!

]]>

I am using the SVYSET COMMAND FIRST:

svyset[pweight=perwt], vce(brr) brrweight(repwtp1-repwtp80) fay(.5)mse

Then running:

svy, subpop(age0_2): mean uninsured, over (Year0809)

However, to run simply 1 year comparing for instance 2008 to 2009 is taking about 2 hours to run.

Any suggestions on how I could get this to run faster and more efficiently?

Thank you!

All best,

Lauren]]>

Im new in Stata programing, and it would be very helpful if someone gave me an opinion about my two problems.

First: I am trying to create a panel setting. woriking with sales data across several countries. Im trying to find the effect on saleid which is the effect of one particular law on the specific products (which are quoted by id) on specific time periods (example december 2013 or july 2012). as you can see in the first attachment.

i already created a group indicator using the commands: egen id1=group(id) and egen date2=group(date) (attachment 2) but when ive try to create the pannel setting using the comand xtset id1 date2 i always get the following comand : repeated time values within panel r(451); also when run only xtset id1 i tells me that the pannel is unbalanced. the only command that i managed to find in internet was to drop if date==date[_n-1] however im not fully covinced that this is a proper way to deal with my data.

my question is can I just go on with xtreg command even in the case of unbalanced pannel, will my estimators be biased ?

Second: in my regression I also trying to enter two fixed effects. the product-date fixed effect and the country-year fixed effect, so that to account for trends in the product and countries. i was just wondering if just an intenaction term between the variables of country and year would do the trick?

Any idea or advice would be highly appreciated.]]>

The Mata code below is the best I came up with for speed. I'm interested in any suggestions or critique. Avoiding looping over measurements certainly helps, and it would be nice to avoid explicitly looping over observations as well.

Code:

// Simulate data set seed 1243 mata mata clear local nmeas = 15 // number of measurements local top = 4 // measurements go from 1, ... top local nobs = 500 local nreps = 50 // for timing only mata: X = ceil(`top ' * runiform(`nobs', `nmeas')) // // Count up agreements mata: N = rows(X) A = J(N, N, .) timer_clear(1) timer_on(1) for (reps = 1; reps <= `nreps' ; reps++) { // outer loop just for timing for (i = 1; i <= N - 1; i++) { for (j = i+1; j <= N; j++) { A[i,j] = rowsum(X[i,.] :== X[j,.]) // avoid loop over measurements } } } timer_off(1) timer() end

I am trying to implement a routine based on the following recent article in the Stata Journal (i've attached it for your convenience):

Terza, J. V. (2017). Two-stage residual inclusion estimation: A practitioners guide to Stata implementation.

I am following the codes on p15, reproduced here:

Step c:

/*step c*/ probit Xe Xo Wplus Step d:

/*step d*/ predict phiWalpha, p gen Xuhat=Y-phiWalpha Step e:

/*step e*/ mata: alphahat=st_matrix("e(b)") ́ mata: Valphahat=st_matrix("e(V)") Step f:

/*step f*/ glm Y Xe Xo Xuhat,family(gaussian) link(probit) vce(robust) Step g:

/*step g*/ mata: betahat=st_matrix("e(b)") ́ mata: Vbetahat=st_matrix("e(V)") mata: Bu=betahat[3] Step h:

/*step h*/ putmata Y Xe Xo Wplus Xuhat mata: X=Xe, Xo, Xuhat, J(rows(Xo),1,1) mata: W=Xo, Wplus, J(rows(Xo),1,1) Step i:

/*step i*/ mata: gradbeta=normalden(X*betahat):*X mata: gradalpha=-Bu:*normalden(X*betahat):*/*

*/normalden(W*alphahat):*W Step j:

/*step j*/ mata: B1 = gradbeta ́*gradbeta mata: B2 = gradbeta ́*gradalpha Step k:

/*step k*/ mata: AVARBeta=invsym(B1)*B2*Valphahat*B2 ́invsym(B1)/* */+ Vbetahat

Step l:

/*step l*/ mata: ACSE = sqrt(diagonal(AVARBeta))

Step m:

/*step m*/ mata: ACtstats=betahat:/ACSE

The goal of these steps is to be able to obtain the asymptotically correct standard errors (ACSE) when implementing the two-stage residual inclusion. I seem to get stuck on step J onwards. The problem is that when I checked the contents of B1 and B2, it seemed to return a full matrix of missing values. As a result, other variables (e.g. AVARBeta, ACSE, ACtstats) from step J onwards (i.e. steps K, L, M) all return missing values.

Not sure if it helps, but when I looked into gradbeta and gradalpha they seemed to have a mix of both missing and non-missing values.

I was wondering if you have any thoughts on this. Any help would be much appreciated.

Thank you very much.

Best,

GuiDeng

]]>