Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- calculating the marginal effect for logistic regression with proc genm...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 08-16-2019 05:12 PM
(2105 views)

Hi,

I'm running a logistic regression in proc genmod for proportion data. I am regressing the share of white students in a school on whether the school is in a city or a suburb. How do I calculate the marginal effects for the city variable? I can't use the margins macro because I'm using the events/trial syntax for proportion data.

```
proc genmod data=dat;
class city;
model n_white/total_students = city/dist=bin link=logit;
run;
```

n_white = number of white students

total_students = number of students in the school

city = indicator for whether a school is in a city or suburb

9 REPLIES 9

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'm not sure what you mean by "marginal" in this situation where you have one X variable. Could you explain further?

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

There are a number of other covariates also in the model, sorry! For example, income inequality ("gini", continuous), charter school ("charter", categorical), urbanicity ("urban", categorical), among many others.

The updated code could look like

```
proc genmod data=dat;
class city;
model n_white/total_students = city gini charter urban/dist=bin link=logit;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Did you check ESTIMATE and SLICE statement.

Or you could use EFFECTPLOT to visualize this marginal effect.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You can use the Margins macro... just modify your aggregated (events/trials) data to create one observation with count for events and one observation with count for nonevents. Then, as mentioned in the Limitations section of the macro documentation, use the FREQ= option in the macro. For example:

```
data drug;
input drug$ x r n @@;
y=1; f=r; output;
y=0; f=n-r; output;
datalines;
A .1 1 10 A .23 2 12 A .67 1 9
B .2 3 13 B .3 4 15 B .45 5 16 B .78 5 13
C .04 0 10 C .15 0 11 C .56 1 12 C .7 2 12
D .34 5 10 D .6 5 9 D .7 8 10
E .2 12 20 E .34 15 20 E .56 13 15 E .8 17 20
;
%Margins(data = drug,
class = drug,
response = y,
roptions = event='1',
freq = f,
dist = binomial,
model = drug x,
margins = drug,
options = diff cl )
```

- Tags:
- marginal effects

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Interesting, I tried your method but got the following error:

ERROR: A cluster has been detected with the frequency counts specified by the FREQ statement unequal within the cluster. The frequency counts must be equal within clusters.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi,

My data are 18,000+ observations, should I attach the csv here? I use the geesubject option because schools are nested within cities and suburbs.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

In that case, you will need to fully expand your aggregated data so that one observation represents a single individual and not use the FREQ= option. For example:

```
data drug;
input drug$ x r n @@;
do i=1 to r; y=1; output; end;
do i=1 to n-r; y=0; output; end;
datalines;
A .1 1 10 A .23 2 12 A .67 1 9
B .2 3 13 B .3 4 15 B .45 5 16 B .78 5 13
C .04 0 10 C .15 0 11 C .56 1 12 C .7 2 12
D .34 5 10 D .6 5 9 D .7 8 10
E .2 12 20 E .34 15 20 E .56 13 15 E .8 17 20
;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

**Don't miss out on SAS Innovate - Register now for the FREE Livestream!**

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.