I am using Stata 13.1 and I am merging postcodes from two different datasets. For the large majority of my observations I have no problems in merging because postcodes coincide (for example I have AB10 in both the master and the using datasets). For a tiny part of my sample I don't have this because the postcodes are specified in different ways in the master and the using datasets. I'll report some examples here:

Example 1:

Master: PO3, PO311, PO330.

Using: PO35, PO36.

Here I would merge on PO3 (in the master dataset).

Example 2:

Master: YO106, YO107, YO104.

Using: YO103, YO105

Here I would merge on YO10 that doesn't exist in any of the datasets.

What I could do, if possible, is to tell Stata "if and only if there isn't a perfect match (like in the AB10 example), merge until the point in which the string variable "postcode" coincides in both the master and the using datasets". Is it possible to do it? How?

Many thanks,

Greta (University of Essex)]]>

Specifically, I want to visualize mean earnings during three years before and after the firm report a special account (call it write-off), using a two-way scatter with connected lines such as :

In data set, not all firms report write-offs, so do and will have a value, while others do not and are assigned a zero value.

In the Y axis , I should have the mean earnings values , and on the X axis, I should have t-3, t-2, t-1 , t , t+1 , t+2, t+3

I calculated the mean value as :

egen mean_writeoff=mean(writeoff) if writeoff !=0, by(yr)

I am not sure how to proceed to get the results I wanted....

Any help ?

Regards

]]>

I think this is simple to code, but I am not sure how to construct a loop for that ?

I would appreciate your help

Thanks

]]>

xtreg depvar income var_one c.var_one#c.var_two i.year, fe

I'd like to graph the relationship between the dependent variable and var_one, but have several lines for each category of values for the time_invariant variable. Basically, be able to see dydx (x being variable one) for different levels of variable two. I created a different version of variable two that categorizes each id according to the quintile it belongs to, and ran xtreg with that version of variable two. Then I run:

margins, dydx(var_one) at(var_two_quint==1) vsquish

margins, dydx(var_one) at(var_two_quint==2) vsquish

margins, dydx(var_one) at(var_two_quint==3) vsquish

margins, dydx(var_one) at(var_two_quint==4) vsquish

margins, dydx(var_one) at(var_two_quint==5) vsquish

I thought that I could then use the command marginsplot to see graphically the effect of var_one at each of the five levels of var_two. Needless to say, this is not quite right. I'd appreciate any thoughts on how to create this overlay plot on one graph.

Thanks,

Adela

]]>

I'm trying to run panel data regression using the prias-winsten command but it tells me i need to tsset. Does Prais also work for xtset? If so which variable do I set? My dependent variables are emissions and dependent variables are GDP, GDP^2, mfg share, and Trade openness. The data are yearly from 1980-2010 for all oedc countries.

Thanks!]]>

mata

function Ex(real matrix G)

{

st_matrix("G") //imports matrix from stata

g=st_matrix("G") //names it "g"

st_matrix("H",g)

}

mata mosave Ex(), replace

end

Then if I try to run the following set of commands in Stata:

quietly varsoc y x, maxlag(12)

matrix define G=r(stats)

mata Ex(G)

I get an error saying that G was not found. I also tried to use mata Ex("`G'") but now the error saying: "Ex(): 3253 <tmp>[1,1] found where real required".

Does anyone knwo where the mistake exactly is and how to correct it?

Thanks in advance for any advice

]]>

Could you please help me in 2 issues:

1/ I need to report adjusted r squared for random effect

I tried the command : display "adjusted R2 = " e(r2_a)!! But it is not appropriate for random effect!! no results are reported!!

2/ I need also to report the Durbin watson test for random effect!!

Thanksss

Hanou!!

]]>

I am using the latabstat command to export summary statistics results from Stata to Latex, and I am getting this weird behavior of the latabstat command transposing the results in Latex with more than one variable. I will show you what I mean in a reproducible data set below:

:

clear set more off set obs 100 gen x1 = rnormal() gen x2 = rnormal() gen x3 = rnormal() latabstat x1, s(mean sd min p25 p50 p75 max) latabstat x1 x2, s(mean sd min p25 p50 p75 max)

Here, I just generated 3 random normal variables. If you run this, the output from the latabstat x1, s(mean sd min p25 p50 p75 max) is given by:

:

. latabstat x1, s(mean sd min p25 p50 p75 max) \begin{table}[htbp]\centering \caption{\label{} \textbf{} }\begin{tabular} {@{} l r r r r r r r @{}} \\ \hline \textbf{variable } & \textbf{ mean} & \textbf{ sd} & \textbf{ min} & \textbf{ p25} & \textbf{ p50} & \textbf{ p7 > 5} & \textbf{ max} \\ \hline x1 & -.1049806 & 1.041148 & -2.705495 & -.8760525 & -.0217751 & .5283152 & 2.457717 \\ \hline \multicolumn{8}{@{}l}{\footnotesize{\emph{Source:} }} \end{tabular} \end{table}

Notice here that the variable, "x1" is in the first row, and the summary statistics are given in each column (mean being the first column, then standard deviation, etc.)

However, once I include multiple variables, the result becomes transposed (i.e.)

:

. latabstat x1 x2, s(mean sd min p25 p50 p75 max) \begin{table}[htbp]\centering \caption{\label{} \textbf{} }\begin{tabular} {@{} l r r @{}} \\ \hline \textbf{ stats } & \textbf{ x1} & \textbf{ x2} \\ \hline mean & -.1049806 & .0160976 \\ sd & 1.041148 & .9938123 \\ min & -2.705495 & -2.738241 \\ p25 & -.8760525 & -.7263283 \\ p50 & -.0217751 & .0748608 \\ p75 & .5283152 & .7048551 \\ max & 2.457717 & 2.318516 \\ \hline \multicolumn{3}{@{}l}{ \footnotesize{\emph{Source:} }} \end{tabular} \end{table}

Now, the variables run along the columns and the summary statistics are denoted by the rows.

I would like summary tables where the each row is a different variable, and each column is a separate summary statistic. Is this possible using the latabstat command?

Thank you all in advance for your help!

Vincent

]]>

I have been using tab and producing each table individually , i.e age by status, ht byu status , but I am sure there is a more efficient way to do this,

I also need to ouput the table , say to excel , and would also appreciate advice on this

thanks

]]>

:

mata: dh = _docx_new() end sysuse auto mata: _docx_add_data(dh, 1, 1, (1,10), ("mpg", "price", "foreign")) end mata: res = _docx_save(dh, "example.docx") end