“Automatically” calculate linear combination of pa

2019-05-24 12:18发布

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.

3条回答
我只想做你的唯一
2楼-- · 2019-05-24 12:26

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.

查看更多
欢心
3楼-- · 2019-05-24 12:29

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.

查看更多
一纸荒年 Trace。
4楼-- · 2019-05-24 12:42

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

查看更多
登录 后发表回答