continuous variable as random effect in proc mixed - sas

I could use some help understanding the interpretation of a continuous variable random effect. I understand the interpretation of fixed effect and categorical random effect. But SAS seems to allow continuous random effect as well (code below). I understand how random effects are supposed to be categorical, but I came across discussions/forums where arguments were made for continuous random effects as well, hence SAS having that option I guess. But , I am more so trying to understand what do I make of the variance estimate and the coefficient estimate you get in such scenario.
For example we are trying to predict wealth based on education and age. And, we made age as random effect. The code would look like
Proc mixed data=data;
model wealth = education;
random age /solution;
run;
I got the covariance parameter estimate for the random effect age.notice i dont have class statement. I understand, it deosn't make sense to have age as random effect, but I am trying to understand whats going on behind in the sas in the above code. Also, is the random coefficient estimate for age which is truncated towards 0 comparable to fixed effect coefficient when age is fixed?
Thanks in advance.

Related

Add stars to p<.05 in correlation matrix in Stata

I'm hoping to one star to p<.05 and two stars to p<.001 in a correlation matrix in Stata. This is the code that I'm currently using. The code still generates a correlation matrix, but no stars appear in places where they should. Thanks for your help!
asdoc corr RELATIONSHIP anxiety BEH_SIM SIM_VALUES sptconf NEG_EFFICACY spteffort SPTEFFORT_OTHER COOP_MOTIV COMP_MOTIV, star(0.5), replace
First, you need to use pwcorr rather than corr to be able to add stars to your correlation matrix. Second, you should not have the second comma right after the star option.
For example, the code below will output a correlation matrix with 1 star if significant at a 10% level, 2 stars if significant at 5% level, and three stars if significant at a 1%
level.
asdoc pwcorr var1 var2 var3, star(all) replace
I do not believe you can specify star numbers and significant levels the way you would like to using asdoc. You can specify custom significance levels by using star(.05) rather than star(all) as I do above, but this will put one star by every correlation coefficient significant at a 5% level and I do not think you can specify more than 1 level at a time.
The author of asdoc is Professor Attaullah Shah. He is very helpful and responsive so you might ask him. If not currently possible, if you ask he may add your suggestion to a future asdoc update. Here is a link to his website: https://fintechprofessor.com/2019/06/01/export-correlation-table-to-word-with-stars-and-significance-level-using-asdoc/

Random Effects Model - Proc HPMIXED vs MIXED Dropped Intercept?

We have a large dataset, and when we run proc mixed or hpmixed on a sample of the data, we get the same coefficients for the continuous variables. However, for HPMIXED, SAS ignores the reference values we give it for categorical variables, and the intercept becomes 0.
Is there an option to force HPMIXED to use an intercept and to 'not ignore' the ref="" values we choose?
Thank you in advance for your help!

Weighted binomial confidence interval in Stata

I am trying to compute a binomial confidence interval for a dummy variable after specifying the survey design in Stata with the svyset command but I get the following error: ci is not supported by svy with vce(linearized)
svyset [pweight=My_weight]
svy: ci Variable, binomial
I have also tried the following code:
ci Variable [pweight=My_weight], binomial
But got the error: pweight not allowed
Binomial confidence intervals are calculated as proportions in Stata 14 (Stata 13 uses binomial). This makes sense because the mean of a dummy variable is the proportion of 1's. Look at the help file here: http://www.stata.com/help.cgi?ci
So you likely want a command like:
ci proportions Variable [pweight=My_weight]
From the help file, it looks like only fweights may be allowed here.
Originally I thought that a better way might be to grab your CI from the means output. Here is an example modified from the svy help file.
webuse nhanes2f
svyset psuid [pweight=finalwgt]
svy: mean sex
But OP is right, this doesn't adjust for the binomial distribution.

Why do I get different regression outputs in SAS and in Stata when using Prais-Winsten estimation?

I have a time series dataset with serious serial correlation problem, so I adopted Prais-Winsten estimator with iterated estimates to fix that. I did the regressions in Stata with the following command:
prais depvar indepvar indepvar2, vce(robust) rhotype(regress)
My colleague wanted to reproduce my results in SAS, so she used the following:
proc autoreg data=DATA;
model depvar = indepvar indepvar2/nlag=1 iter itprint method=YW;
run;
For the different specifications we ran, some of them roughly match, while others do not. Also I noticed that for each regression specification, Stata has many more iterations than SAS. I wonder if there is something wrong with my (or my colleague's) code.
Update
Inspired by Joe's comment, I modified my SAS code.
/*Iterated Estimation*/
proc autoreg data=DATA;
model depvar = indepvar indepvar2/nlag=1 itprint method=ITYW;
run;
/*Twostep Estimation*/
proc autoreg data=DATA;
model depvar = indepvar indepvar2/nlag=1 itprint method=YW;
run;
I have a few suggestions. Note that I'm not a real statistician and am not familiar with the specific estimators here, so this is just a quick read of the docs.
First off, the most likely issue is that it looks like SAS uses the OLS variance estimation method. That is, in your Stata code, you have vce(robust), which is in contrast to what I read SAS as using, the equivalent of vce(ols). See this page in the docs which explains how SAS does the Y-W method of autoregression, compared to this doc page that explains how Stata does it.
Second, you probably should not specify method=YW. SAS distinguishes between the simple Y-W estimation ("two-step" method) and iterated Y-W estimation. method=ITYW is what you want. You specify iter, so it may well be that you're getting this anyway as SAS tends to be smart about those sorts of things, but it's good to verify.
I would suggest actually turning the iterations off to begin with - have both do the two-step method (Stata option twostep, SAS by removing the iter request and specifying method=YW or no method specification). See how well they match there. Once you can get those to match, then move on to iterated; it's possible SAS has a different cutoff than Stata and may well not iterate past that.
I'd also suggest trying this with only one independent and dependent variable pair first, as it's possible the two programs handle things differently when you add in a second independent variable. Always start simple and then add complexity.

"Automatically" calculate linear combination of parameter estimates with PROC GLM

Background: I have a categorical variable, X, with four levels that I fit as separate dummy variables. Thus, there are three total dummy variables representing x=1, x=2, x=3 (x=0 is baseline).
Problem/issue: I want to be able to calculate the value of a linear combination (i.e. using SAS as a calculator) of these dummy variables. For example, 2*B1 + 2*B2 + B3.
In Stata, this can be done using the lincom command, which uses the stored beta estimates to calculate linear combinations of the parameters.
In SAS in a procedure such as PROC GLM, I think I should use the ESTIMATE statement, but I'm not sure how I would specify the "weights" for each variable in this case.
You are looking for PROC SCORE. This takes output regression or factor estimates and scores a new data set. See here for an example. http://support.sas.com/documentation/cdl/en/statug/66859/HTML/default/viewer.htm#statug_score_examples02.htm
FYI, PROC MODEL does allow this in the model statement, which may be less work than PROC SCORE. I know PROC MODEL can be used readily in place of PROC REG, but I'm not sure how advanced of modeling PROC MODEL does, so it may not be an option for more complex models. I was hoping for something with less coding, but given the nature of SAS, I think this and PROC SCORE are the best I'm going to get.
What if you add your linear combination as a variable in your input dataset?
data myDatasetWithLinCom;
set mydata;
LinComb=2*(x=1)+ 2*(x=2)+(x=3); /*equvilent to 2*B1 + 2*B2 + B3*/
run;
then you can specify LinComb as one of the explanatory variables and you can lookup the coefficient directly from the output.