Dear members of the list,
I have a dataset with individual-level data nested in years and countries. I am interested in plotting the marginal effect of gender on overeducation (my dependent variable) against the country-level scores of a key independent variable (gender egalitarianism). I'm having problems running the loop that should generate and store those marginal effects (see below). That's the reason I'm asking for help here.
First, I run a simple logistic regression with years as a control and an interaction of gender and country. S020 is the variable that captures years. As I said before, my intention is to get the marginal of gender for each country. See next:
Before the loop, I generate unique country codes with 'levelsof'
It works. So far, so good.
Then, I create variables to store the results:
Now comes the loop, where the variables above are included. This is where Stata reads but does nothing. It does not give any error message either.
I wonder why the loop does not work.
Once the marginal effect of gender for the different countries is generated, I would plot these marginal effects against gndr_egalitarianism per country. For this, I would merge the small dataset with the marginal effect of gender by country with another dataset with the country values of gender egalitarianism.
But that's another story. First I have to solve the problem with the loop mentioned before
As indicated in the norms of the list, I'm pasting a sample of my data with dataex.
Thanks for your attention
And kind regards
Luis Ortiz
I have a dataset with individual-level data nested in years and countries. I am interested in plotting the marginal effect of gender on overeducation (my dependent variable) against the country-level scores of a key independent variable (gender egalitarianism). I'm having problems running the loop that should generate and store those marginal effects (see below). That's the reason I'm asking for help here.
First, I run a simple logistic regression with years as a control and an interaction of gender and country. S020 is the variable that captures years. As I said before, my intention is to get the marginal of gender for each country. See next:
HTML Code:
logit overed4 i.female##i.country S020
HTML Code:
levelsof cntry, local(countries)
Then, I create variables to store the results:
HTML Code:
gen country_effect = . gen country_id = .
HTML Code:
foreach c of local countries { margins, dydx(female) at(cntry=`c') matrix b = r(b) replace country_effect = b[1,1] if country == `c' replace country_id = `c' if country == `c' }
Once the marginal effect of gender for the different countries is generated, I would plot these marginal effects against gndr_egalitarianism per country. For this, I would merge the small dataset with the marginal effect of gender by country with another dataset with the country values of gender egalitarianism.
But that's another story. First I have to solve the problem with the loop mentioned before
As indicated in the norms of the list, I'm pasting a sample of my data with dataex.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input float overed4 byte female int(cntry S020) float mean_gndr_eg 0 1 276 1997 .638171 0 1 276 1997 .638171 1 2 276 1997 .638171 0 2 276 1997 .638171 0 2 276 1997 .638171 0 2 276 1997 .638171 0 2 276 1997 .638171 0 2 276 1997 .638171 0 1 276 1997 .638171 0 1 276 1997 .638171 0 1 724 1997 .624891 0 1 7241997 .624891 0 1 7241997 .624891 0 2 7241997 .624891 0 2 724 1997 .624891 0 1 724 1997 .624891 0 2 724 1997 .624891 0 1 724 1997 .624891 0 1 724 1997 .624891 0 2 724 1997 .624891 end label values female X001 label def X001 1 "Male", modify label def X001 2 "Female", modify label values cntry S003 label def S003 276 "276. Germany", modify label values S020 S020 label def S020 1997 " 1997", modify label var female "Sex" label var cntry "Country (ISO 3166-1 Numeric code)" label var S020 "Year survey"
And kind regards
Luis Ortiz
Comment