store model coeficients and standard errors using postfile stata 15 - stata

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'

Related

Suest after AME- dy/dx not saving for suest

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]

saving extracted statistic from regression in a dataset: Stata

I wonder if you could help me figure it out a quite simple question of how I can save an extracted statistic from a regression in a separate dataset (or file), and also add more statistics from the other regression to it later?
For example, the statistic from one regression can be extracted as e(f) and from another one is also as e(f).
Roger Newson's parmest is great for dealing with "resulsets," which are Stata datasets created from the output of a Stata command. The help file has a nice example of combining three regressions into a single file that I modified here to include R^2 [stored in e(df_r)]:
sysuse auto, clear
tempfile tf1 tf2 tf3
parmby "reg price weight", lab saving(`"`tf1'"', replace) idnum(1) idstr(M1) escal(r2)
parmby "reg price foreign", lab saving(`"`tf2'"', replace) idnum(2) idstr(M2) escal(r2)
parmby "reg price weight foreign", lab saving(`"`tf3'"', replace) idnum(3) idstr(M3) escal(r2)
drop _all
append using `"`tf1'"' `"`tf2'"' `"`tf3'"'
list idnum idstr es_1, noobs nodis

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