Plot specific fixed-effect variable with multiple outcomes using coefplot - stata

I run a regression with a fixed-effect that has multiple outcomes. I want to only plot that fixed-effect variable. I don't like the way coefplot does the ticks and labels. Let me give an example.
sysuse auto
reg price i.rep78
coefplot, vertical drop(_cons)
Now the x-ticks are "Repair Record 1978=2", ... "Repair Record 1978=5". This is very lengthy. I will only plot this variable, so I would rather have the "Repair Record 1978" elsewhere, either in title or as a legend. The x-ticks I would rather have only "2", "3", .. "5". How could I achieve something like this the easiest using coefplot?

You can give the coefficients different names with the rename option, and to control the look of the graph you can use twoway options documented in help twoway_options.
Example:
coefplot, vertical drop(_cons) rename(*.rep78 = "") title("Repair Record 1978")
The best way to find out about options in coefplot would be to type in Stata: help coefplot

Related

Rename estimate for the constant for coefplot

I want to create in Stata a coefplot variable: however, in one of the models I want to show there is no value for the estimate which I report, but instead I want to report the constant.
How is that possible?
sysuse auto, clear
regress price weight
coefplot, drop(weight) rename(_cons = abcdef)

Tabulate relative frequencies in Stata

I am trying to tabulate frequencies for a variable divided in two groups. That is, I would like to see how much a variable takes value "Yes" divided by both region and sex. Now, this is easy to do in Stata using "tab" and option row, but I have trouble exporting it. To make it clear, I am able to build the table with absolute frequencies in this way:
eststo formalyes: estpost tab regionwb_c female if fin22a==1
eststo formalno: estpost tab regionwb_c female if fin22a==0
eststo formalt: estpost tab regionwb_c female
estout formalyes formalno formalt using summformal.tex, replace varlabels(`e(labels)') unstack booktabs ///
mgroups("Yes" "No" "Tot", pattern(1 1 1) prefix(\multicolumn{#span}{c}{) suffix(}) span erepeat(\cmidrule(lr){#span})) fragment
This, put in my latex code, produces this relatively nice table:table1
Now what I would like to do is to reproduce the exact same table, but to have the relative and not absolute frequencies there. Now normally to my understanding if you want the relative frequencies you can have
tab x y, row nofreq
but if you try to combine this with estpost it does not work. Are there any hints? I tried working it out with tabout, but all i was able to produce is this:
tabout regionwb_c female using trial.tex, replace percent style(tex) c(mean fin22a) sum
Which gives this:table2
Where, as you can see, I am pretty lost. I am sorry if the question sounds silly but I struggled finding results online or on the tabout manual. I hope somebody can help me.
I have not worked with tabout before, but maybe one way to work around it could be to just program new variables containing the male and female relative frequencies by regionwb_c using the egen command for example (like in this link enter link description here. Then you could just pass these relative frequencies variables in your table.
Could that maybe help you? Good Luck!

How to change SAS sgplot refline label orientation

I am plotting in SAS using SGPLOT. I added a few reflines on the x-axis to mark certain dates however, the labels of these reflines become vertical as shown here. With only three reflines, the labels were horizontal as I hoped. However, as I added more reflines, the labels turned vertical.
Is there a way to change the orientation of the label? Or is it just because there is not enough space...
Here is my code for the refline:
refline '01Jul2002'd / axis=x label = "[1]"
labelloc=outside labelpos=max labelattrs=(size=6.5pt family="arial")
SAS is automatically rotating them in an attempt to "fit" them (or to indicate they're overlapping visually), more than likely. Using Reeza's example, this is trivial to reproduce.
proc sgplot data=sashelp.stocks(where=(stock='IBM'));
series x=date y=open;
refline '01Jul2002'd / axis=x label = "[1]"
labelloc=outside labelpos=max labelattrs=(size=6.5pt family="arial");
refline '02Jul2002'd / axis=x label = "[2]"
labelloc=outside labelpos=max labelattrs=(size=6.5pt family="arial");
run;
With just one, it is horizontal, but the second one causes a rotation.
I don't see a way to fix this other than having fewer reference lines so that the labels don't try to overlap. Neither SGPLOT nor GTL seems to give an option (usually named FITPOLICY) for reference line plots. You could use a different kind of plot I suppose which might give you more options, or use annotation rather than reference lines (it's possible to duplicate reference lines entirely using Annotation, the refline plot itself is just a convenience to avoid having to use the Annotate facility).
You may want to consider asking this question on http://communities.sas.com and seeing if one of the developers (Sanjay, Dan H, etc.) has a workaround or can suggest something specific other than annotation. If you do I suggest you include an example like the above so the question is clear.
I cannot replicate your issue. Here's code that doesn't replicate your issue. This means either you've set something else somewhere else that's causing this or you could be using a different version. I'm on SAS 9.4 TS1M3. In the future please include code so we can replicate your issue.
proc sgplot data=sashelp.stocks(where=(stock='IBM'));
series x=date y=open;
refline '01Jul2002'd / axis=x label = "[1]"
labelloc=outside labelpos=max labelattrs=(size=6.5pt family="arial");
run;

Drop random effects parameters from output table in Stata

I want to create a regression table (using esttab) from a mixed-effects regression estimated via xtmixed in Stata, but I want the output without the random effects parameters. How can I drop the random effects parameters from the output table? E.g., in the case of two variables...
xtmixed (Dependent Variable) (Independent variable) || (Grouping Variable))
... I don't want the lns1_1_1 and the lnsig_e values in my esttab-table. What is the best way to do this?
There is a keep() and a drop() option. For example:
webuse productivity, clear
xtmixed gsp private emp hwy water other unemp || region: || state:, mle
estimates store m1
// check result names
matrix list e(b)
// with -keep()- option
estout m1, keep(private emp hwy water other unemp gsp:_cons)
// with -drop()- option
estout m1, drop(lns1_1_1:_cons lns2_1_1:_cons lnsig_e:_cons)
In the context of multiple equation estimation, resulting matrices have elements with two-part names. The general form is equation-name:varname. The result of matrix list shows this. Afterwards, just use the appropriate names in the keep() and drop() options.
See [U] 14.2 Row and column names for more details on the naming conventions.
(Recall esttab is a wrapper for estout.)

Stata: adding coefficients to estout

I want to output the results of several regressions as a nicely formatted LaTeX table and am happy to see that for most cases the estout package on SSC seems to do exactly that.
However, what I want is a bit special: Between the table section that shows the coefficient estimates and their standard errors, and the section that shows R^2 and the like, I would like to add a section that shows point estimates and standard errors (bonus points for stars) for particular linear combinations of the coefficients. Both point estimates and standard errors are easily computed via lincom but the best solution I've found so far for getting these numbers into the table involves the massily hacky addition of these numbers, one estadd scalar ... at a time. Is there a more elegant way to do this?
Example code:
sysuse auto
eststo, title("Model 1"): regress price weight mpg
lincom weight+mpg
estadd scalar skal r(estimate)
estadd scalar skalsd r(se)
eststo, title("Model 2"): regress price weight mpg foreign
lincom weight+mpg
estadd scalar skal r(estimate)
estadd scalar skalsd r(se)
label variable foreign "Car type (1=foreign)"
estout, cells(b(star fmt(3)) t(par fmt(2))) ///
stats(skal skalsd r2 N, labels("Linear Combination" "S.E." R-squared "N. of cases")) ///
label legend varlabels(_cons Constant)
You can use the layout, star and fmt sub-options to format the added scalars like this:
estout, cells(b(star fmt(3)) t(par fmt(2))) ///
stats(skal skalsd r2 N, layout(# (#) # #) star(skal) labels("Linear Combination" "S.E." R-squared "N. of cases") fmt(%9.2f %9.2f %9.2f %12.0f)) ///
label legend varlabels(_cons Constant)
These options are documented here. As far as I know, the method in your question is the only way to do this.
There's a problem with the answer above. I think the original poster wanted statistical significance stars based on a test of the lincom (weight+mpg) vs zero. That is not what star(skal) does.
As the documentation states: star[(scalarlist)] to specify that the overall significance of the model be denoted by stars. The stars are attached to the scalar statistics specified in scalarlist." Emphasis mine.
star(skal) in the previous example will place significance stars next to the estimates of skal, but they will be from an F-test of the overall significance of the regression model (I think). Not from lincom.
When I use this strategy on other specifications, the stars attached are clearly not based on the ones from lincom. I'm not sure if it's possible to use lincom/esttab to get the stars from lincom. To say nothing of nlcom!