BookmarkSubscribeRSS Feed
SASNovice2014
Calcite | Level 5

Hello,

 

I have an unbalanced panel dataset across 10 years as follows. Here are my variables:

 

Y= dependent variable

x1= predictor

x1_2 = predictor (squared)

x3 = moderator

 

name time gvkey y x1 x1_2 x3
abc 1 10553 0.95 -0.20 0.04 0.34
abc 2 10553 1.20      
abc 3 10553 1.29 -0.45 0.20 0.44
abc 4 10553 1.62 -0.32 0.10 0.23
           
xyz 1 7435 1.97 -1.09 1.19  
xyz 2 7435 1.86 -0.69 0.48 0.41
xyz 3 7435 1.90 -0.70 0.49 0.42
xyz 4 7435 1.94 -1.90 3.62 2.67

 

Here's SAS codes to run regression where x3 has been split into high sample:

 

proc panel data=test_xlag ;

inst depvar

exogenous=( x3_high )

pred=(x1  x1_2)  ;

model y_high =  x3_high   x1   x1_2 

/ gmm  twostep maxband=1 time robust ;

     id gvkey time;

run;

 

Here's SAS codes to run regression where x3 has been split into low sample:

 

proc panel data=test_xlag ;

inst depvar

exogenous=( x3_low )

pred=(x1  x1_2)  ;

model y_low = x3_low   x1   x1_2 

/ gmm  twostep maxband=1 time robust ;

     id gvkey time;

run;

 

Here's SAS codes to run both regressions in a DO LOOP:

 

data test_xlag;

do X1 = -3.0 to 0 by 0.1;

      y_high = 0.136544 + (-0.04991)*X1 + (-0.00773)*X1*X1 ;

      y_low  = 0.152363 + (-0.05342)*X1 + (-0.00836)*X1*X1 ;

    output;

    end;

run;

 

Let's assume I've created the ANNOTATE dataset and produce the plot in the attached file. The plot is an inverse U-shaped curve. It has 2 parallel curvilinear lines (red curve = depicts regression based on high sample, blue curve = depicts regression based on low sample). In the plot, x axis is range of x1 values, and y axis is range of y values.

 

Here are my questions:

 

(1) How do create a DO LOOP in SAS 9.3 that would allow me to statistically compare the red line to the blue line for x1 ranging from -0.1 to -1.0 at increments of 0.1? How do I test whether the red line is statistically different from the blue line at each specified values of x1? I would need chi-square values and p-values for each set of red/blue comparisons at each of the ten x1 values.

 

(2) How do I generate marginal effects and standard errors for each of blue line and red line at each of the 10 specified x1 values (for a total of 20 values)? What SAS procedure do I use?

 

Below are the STATA codes to generate what I need for (1) and (2). Can someone help me translate these STATA codes into SAS codes?

 

margins, at(x1 = (-0.1 (0.1) -1.0) x3_high=(0 1 )) post

margins, coeflegend

forvalues i = 1(2)20 {

loc j = `i' +1

test _b[`i'._at] = _b[`j'._at]

}

 

Thanks in advance!

1 REPLY 1
SASNovice2014
Calcite | Level 5

 

Hello,

 

I have an unbalanced panel dataset across 10 years as follows. Here are my variables:

 

Y= dependent variable

x1= predictor

x1_2 = predictor (squared)

x3 = moderator

 

name time gvkey y x1 x1_2 x3
abc 1 10553 0.95 -0.20 0.04 0.34
abc 2 10553 1.20      
abc 3 10553 1.29 -0.45 0.20 0.44
abc 4 10553 1.62 -0.32 0.10 0.23
           
xyz 1 7435 1.97 -1.09 1.19  
xyz 2 7435 1.86 -0.69 0.48 0.41
xyz 3 7435 1.90 -0.70 0.49 0.42
xyz 4 7435 1.94 -1.90 3.62 2.67

 

Here's SAS codes to run regression where x3 has been split into high sample:

 

proc panel data=test_xlag ;

inst depvar

exogenous=( x3_high )

pred=(x1  x1_2)  ;

model y_high =  x3_high   x1   x1_2 

/ gmm  twostep maxband=1 time robust ;

     id gvkey time;

run;

 

Here's SAS codes to run regression where x3 has been split into low sample:

 

proc panel data=test_xlag ;

inst depvar

exogenous=( x3_low )

pred=(x1  x1_2)  ;

model y_low = x3_low   x1   x1_2 

/ gmm  twostep maxband=1 time robust ;

     id gvkey time;

run;

 

Here's SAS codes to run both regressions in a DO LOOP:

 

data test_xlag;

do X1 = -3.0 to 0 by 0.1;

      y_high = 0.136544 + (-0.04991)*X1 + (-0.00773)*X1*X1 ;

      y_low  = 0.152363 + (-0.05342)*X1 + (-0.00836)*X1*X1 ;

    output;

    end;

run;

 

Let's assume I've created the ANNOTATE dataset and produce the plot in the attached file. The plot is an inverse U-shaped curve. It has 2 parallel curvilinear lines (red curve = depicts regression based on high sample, blue curve = depicts regression based on low sample). In the plot, x axis is range of x1 values, and y axis is range of y values.

 

Here are my questions:

 

(1) How do create a DO LOOP in SAS 9.3 that would allow me to statistically compare the red line to the blue line for x1 ranging from -0.1 to -1.0 at increments of 0.1? How do I test whether the red line is statistically different from the blue line at each specified values of x1? I would need chi-square values and p-values for each set of red/blue comparisons at each of the ten x1 values.

 

(2) How do I generate marginal effects and standard errors for each of blue line and red line at each of the 10 specified x1 values (for a total of 20 values)? What SAS procedure do I use?

 

Below are the STATA codes to generate what I need for (1) and (2). Can someone help me translate these STATA codes into SAS codes?

 

margins, at(x1 = (-0.1 (0.1) -1.0) x3_high=(0 1 )) post

margins, coeflegend

forvalues i = 1(2)20 {

loc j = `i' +1

test _b[`i'._at] = _b[`j'._at]

}

 

Thanks in advance!

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1215 views
  • 0 likes
  • 1 in conversation