Suest after AME- dy/dx not saving for suest - stata

After running these command all day, my head is on fire, I am now reaching out.
Please don't direct me to papers about Suest that are commonly mentioned on the web, I already checked them.
It seems there is a problem with storing the dy/dx values of the AME to merge between different models in the suest command in order to perform the test command.
What I would like to test is if the AME of the lower class/upper class/middle class in one regime/context is statistically significant from the lower class situated in another regime/context.
Dependent variable: 3 categories: renter, mortgaged homeownership, outright homeownership.
*Liberal_market
mlogit owner_housing_debt2 United_States United_Kingdom Swizerland c.age_centered
ib0.lower_class ib0.upper_class if homeownership_regimes==1 ,
baseoutcome(1)
margins , dydx(lower_class upper_class) coeflegend post
est store Liberal_market
*Family_financial_support
mlogit owner_housing_debt2 Belgium Finland France Ireland Luxembourg Norway Spain
ib0.lower_class ib0.upper_class if homeownership_regimes==2 , baseoutcome(1)
margins , dydx(lower_class upper_class) coeflegend post
est store Family_financial_support
est table Liberal_market Family_financial_support
suest Liberal_market Family_financial_support
**In the end, this is what I want to do:
test [Liberal_market]1.lower_class =[Family_financial_support]1.lower_class
*error message
Liberal_market was estimated with a nonstandard vce (delta)
r(322);
-Unfortunately, the following answer from Statalist regarding the nonstandard vce in suest- didn’t help me either
https://www.statalist.org/forums/forum/general-stata-discussion/general/1511169-can-not-use-suest-for-margins-after-probit-or-regress
Will appreciate your solution:)

Thank you. I tried your recommendation. Unfortunately, I could not find an organized document with examples for xlincom with margins.
I tried the following code, but my problem is withdrawing the margins of the independent variable categories (1.lower_class and 1.upper_class) from the 2 separate mlogit reg after suest. I mean, how to define in the command that I want 1.lower class from model A and 1.lower_class from model B in the margins and in the xlincom. Please see my example below:
mlogit owner_housing_debt2 ib0.lower_class ib0.upper_class if regime==1,
baseoutcome(1)
est store A
mlogit owner_housing_debt2 ib0.lower_class ib0.upper_class if regime==2,
baseoutcome(1)
est store B
suest A B
margins 1.lower_class 1.upper_class, coeflegend post
lincom _b[1.lower_class] - _b[1.upper_class]

Related

store model coeficients and standard errors using postfile stata 15

I want to transfer model estimates from Stata to R. I found on Stack Overflow the suggestion to do this using postfile. Since my Stata knowledge is limited I followed a guide from Arizona University (https://jearl.faculty.arizona.edu/sites/jearl.faculty.arizona.edu/files/CR2%20Post.pdf).
At the end you can see the code I deducted from this guide. However, I was unsuccessful and received l.log_imputed_welfarespending_pc_b invalid name as an error. Can anyone spot my mistake or propose an alternative way to export the models estimates to R?
xtlogit priowaronset2 c.l.log_imputed_welfarespending_pc##c.l.transnational_rebels l.gdplog l.poplog l.polity2 oil nbs_civilwar nbs_trade nbs_dem noncontiguity relfrac gdppcgrowth mountaniousterrain l.decaywarprio10 asia ssafrica lamerica eeurop western nafrme if year>1974,re vce(robust)
tempname memhold
postfile `memhold'
l.log_imputed_welfarespending_pc_b l.transnational_rebels_b l.log_imputed_welfarespending_pc##c.l.transnational_rebels_b l.log_imputed_welfarespending_pc_se l.transnational_rebels_se l.log_imputed_welfarespending_pc##c.l.transnational_rebels_se using "modelcoef.dta", replace
xtlogit priowaronset2 c.l.log_imputed_welfarespending_pc##c.l.transnational_rebels l.gdplog l.poplog l.polity2 oil nbs_civilwar nbs_trade nbs_dem noncontiguity relfrac gdppcgrowth mountaniousterrain l.decaywarprio10 asia ssafrica lamerica eeurop western nafrme if year>1974,re vce(robust)
post `memhold' (_b[l.log_imputed_welfarespending_pc]) (_se[l.log_imputed_welfarespending_pc]) (_b[l.transnational_rebels]) (_se[l.transnational_rebels]) (_b[l.log_imputed_welfarespending_pc##c.l.transnational_rebels]) (_se[l.log_imputed_welfarespending_pc##c.l.transnational_rebels])
postclose `memhold'

Stata pie chart error

Hi I'm trying to create a pie chart that has a lot of slices. For some reason I get an error when running this code.
My code
graph pie ccounter if year==1900 & ccounter>100 & labforce==2, over(occ1950)
and I get this error
(note: areastyle p193pie not found in scheme, default attributes used)
(note: areastyle p194pie not found in scheme, default attributes used)
(note: areastyle p195pie not found in scheme, default attributes used)
(note: areastyle p196pie not found in scheme, default attributes used)
option min() incorrectly specified
Note that the variable occ1950 has more than 100 values. I don't know whether this is what causing the problem.
Extra Information
I use this code to create the variable ccounter
bys mcdstr year occ: gen counter=_n
bys mcdstr year occ: egen ccounter=max(counter)
I used this to calculate the number of people working in each industry by year and location.
The problem lies in that the variable occ1950 has too much unique values. Let us examine the problem using a CSV dataset of only 40 countries.
country,fdi
Afghanistan,141.391
Algeria,541.478
Angola,238.637
Antigua and Barbuda,1.653
Argentina,205.691
Bahamas,21.927
Bahrain,1.317
Bangladesh,50.298
Barbados,2.816
"Bolivia, Plurinational State of",41.572
Botswana,87.649
Brazil,455.5649999999999
British Virgin Islands,12387.568
Brunei Darussalam,21.02
Cambodia,672.6800000000001
Cameroon,30.159
Cape Verde,3.783
Cayman Islands,15323.116
Chile,53.149
Colombia,49.047
Congo,112.104
"Congo, Democratic Rep. of",302.505
Costa Rica,.826
Côte d' Ivoire,27.099
Dominican Republic,.112
Ecuador,93.673
Egypt,191.59
Equatorial Guinea,80.21700000000001
Eritrea,16.269
Ethiopia,205.824
Fiji,38.742
Gabon,76.66500000000001
Ghana,129.068
Guinea,97.413
Guyana,79.899
Honduras,2.6
"Hong Kong, China",124987.422
India,291.567
Indonesia,850.0709999999999
"Iran, Islamic Republic of",480.71
After loading this into Stata 14, we can observe that
graph pie fdi, over(country)
produces the error: option min() incorrectly specified.
If we now reduce the dataset to simply 30 countries by: drop _n > 30. We would be able to get a pie chart.
This suggests that you should collapse your data, take the n categories with the largest ccounter and then classify the other classes as "other".
The magic number is 36. So you can have at most 36 unique categories in your pie chart.

create latex output for ivprobit?

Suppose I want to create the latex output for the example in ivprobit. That is:
use http://www.stata-press.com/data/r11/laborsup.dta
ivprobit fem_work fem_educ kids (other_inc = male_educ), first
margins, dydx(_all) pred(pr)
I want to have one column with the first stage, and one with the marginal effects.
What is the best way of doing this?
There might be a more clever way of doing this that does not involve re-estimating the first stage:
webuse laborsup
ivprobit fem_work fem_educ kids (other_inc = male_educ), first
margins, dydx(_all) predict(pr) post
estimates store ivp
reg other_inc male_educ fem_educ kids
estimates store first_stage
estout first_stage ivp, style(tex)

Calculating the Gini Coefficient from LIS data (in Stata)

I need to calculate the Gini coefficient from disposable personal income data at LIS. According to a LIS training document, the Stata code to do this is:
di "** INCOME DISTRIBUTION II – Exercise 13 **"
program define bottop
qui sum ey [w=hweight*d4]
replace ey = .01*r(mean) if ey<.01*r(mean)
qui sum dpi [w=hweight*d4], de
replace ey = (10*r(p50)/(d4^.5)) if dpi>10*r(p50)
end
foreach file in $us00h $fi00h {
display "`file'"
use hweight d4 dpi if (!mi(dpi) & !(dpi==0)) using "`file'", clear
gen ey=dpi/(d4^0.5)
bottop
ineqdeco ey [w=hweight*d4]
}
I have simply copied and pasted this code from the training document. The snippets
qui sum ey [w=hweight*d4]
replace ey=0.01*r(mean) if ey<0.01*r(mean)
and
qui sum dpi [w=hweight*d4], de
replace ey=(10*r(p50)/(d4^0.5)) if dpi>10*r(p50)
are bottom and top coding, respectively.
When I tried to run this code, the variable hweight was not found. Does anyone know what the new name of hweight is at LIS? Or can anyone suggest how I might otherwise overcome this impasse?
I'm familiar with stata, but the sophistication of this code is beyond my ken.
Much appreciated.
Based on the varaiable definition list at the LIS Documentation page, it looks like the variable is now called HWGT
This is more of a second-best solution. However, the census of population provides income by brackets. If you are willing to do that, you can get the counts for every bracket. Have a top-coded bracket for the last one. Use the median income value within each bracket. Then you can directly apply the formula for the Gini coefficient. It is a second best because it is an approximation for the individaul-level data.
Why don't you try the fastgini command:
http://www.stata.com/statalist/archive/2007-02/msg00524.html
ssc install fastgini
fastgini income
return list
this should give you the gini for the variable income.
This package also allows for weights. Type
help fastgini
for more information

Working out the bounding box of a coutnry

I'm wondering if there is a service that to get a set of lat,long points that when connected into a polygon show the outline of a country
Ideally I would like to search by country, and get back an array of lat,long coordinates. Is there such a service?
IF you are happy to consider not using a webservice, this data is available at varying resolutions from Natural Earth. The data is in the public domain.
have a closer look here;
http://en.wikipedia.org/wiki/User:The_Anome/country_bounding_boxes
User:The Anome/country bounding boxes A first hack, based on all
places in the NGA GNS dataset, not (yet) properly handling latitude
wrap-round at ±180°. Country names are mapped from FIPS country codes.
This works pretty well for all countries that do not cross the 180°
meridian. Russia is a notable exception. This dataset does not include
the United States.
country longmin latmin longmax latmax
AA -70.983 12.400 -69.850 12.617
Antigua_and_ -62.417 16.817 -61.650 17.750
United_Arab_ 45.000 22.167 59.250 26.133
Afghanistan 60.433 29.150 75.033 38.484
Algeria -8.700 18.027 70.554 37.203
Azerbaijan 44.783 38.417 50.858 41.911
Albania 19.000 39.583 21.050 42.659
Armenia 43.443 38.857 46.589 41.300
Andorra 1.417 42.433 1.783 42.650
Angola 10.000 -33.806 24.350 -3.033
Argentina -73.533 -58.583 -53.367 -21.783
Australia 112.467 -55.050 168.000 -9.133
AT 122.983 -12.667 124.050 -12.000
Austria 1.200 46.373 19.000 49.017
AV -63.667 18.150 -62.917 18.600
Bahrain 45.000 25.000 50.954 26.566
Barbados -59.667 12.967 -59.383 13.333
Botswana 20.000 -28.517 29.350 24.583
BD -64.908 32.233 -64.617 32.417
Belgium 2.367 49.500 6.400 51.683
Bahamas -86.000 20.000 -70.000 29.547
Bangladesh 84.000 20.600 92.683 26.817
Belize -89.950 15.000 -75.000 18.483
Bosnia_and_H 15.746 42.558 19.671 45.268
Bolivia -69.650 -26.867 -57.550 9.678
Burma 91.833 6.000 102.000 28.350
Benin -4.000 5.000 92.219 21.322
Belarus 22.550 50.717 32.850 56.133
Solomon_Isla -130.000 -45.000 170.200 3.751 WRAPPED
Brazil -73.817 -33.733 -28.850 16.800
BS 39.700 -21.417 39.700 -21.417
Bhutan 80.000 26.217 92.717 30.000
Bulgaria 22.371 41.000 28.600 44.215
BV 3.278 -54.467 3.483 -54.386
Brunei 110.000 -2.000 120.000 15.000
Yahoo! GeoPlanet, the service Stack Overflow are using for their careers site seems to do bounding boxes.
Here is a blog post with detailed query examples.
This repo contains a set of square bounding boxes. Example below:
{
"AF": ["Afghanistan", [60.5284298033, 29.318572496, 75.1580277851, 38.4862816432]],
"AO": ["Angola", [11.6400960629, -17.9306364885, 24.0799052263, -4.43802336998]],
"AL": ["Albania", [19.3044861183, 39.624997667, 21.0200403175, 42.6882473822]],
"AE": ["United Arab Emirates", [51.5795186705, 22.4969475367, 56.3968473651, 26.055464179]],
"AR": ["Argentina", [-73.4154357571, -55.25, -53.628348965, -21.8323104794]],
"AM": ["Armenia", [43.5827458026, 38.7412014837, 46.5057198423, 41.2481285671]],
"AQ": ["Antarctica", [-180.0, -90.0, 180.0, -63.2706604895]],
"…"
}
Full set of boxes:
https://github.com/sandstrom/country-bounding-boxes