Quantcast
Channel: Statalist
Viewing all 65099 articles
Browse latest View live

Data Set required for Economic Turmoil and Conflict

$
0
0
Hello
I am looking for two dataset to create dummy variables from.
1. Regarding Economic Turmoil
ex. Global Financial Crisis of 2007-2008

2. Civil/Political conflict or unrest

Any advise on where to get them or a link perhaps.
Thank you

Zahin

(Country) fixed effects for bilateral trade data in gravity model

$
0
0
Hello everyone,

I'm currently working on a Gravity Model and I'm quite confused about how to properly set up the fixed effects model.

I have bilateral trade data in the following form:
Country_i Country_j Year DepententVar IndepententVar PairID
A B 2000 1232 2736 AB
A B 2001 1234 2536 AB
A B 2002 2716 2352 AB
B C 2000 3242 3435 BC
B C 2001 2342 2354 BC
B C 2002 2344 3345 BC
Now, I would like to add time fixed effects and afterwards country fixed effects in a separate regression.
My understanding is, I have to use xtset and then xtreg instead of reg, because I have time values. So I set up:
Code:
xtset PairID Year, yearly
For the time fixed effects I then use
Code:
xtreg DependentVar IndependentVar i.Year, fe robust
For the country fixed effects I use
Code:
xtreg DependentVar IndependentVar i.Country_i i.Country_j i.Year, fe robust
Now, I noticed the results of these two regressions are exactly the same. Which, after I thought about it, makes sense, as I set up xtset with PairID and Year.
I searched the forum and the internet about how to set up fixed effects in a bilateral model (or gravity model) properly and came across the following code:
Code:
tab (Year), gen (Year_)
egen expyear = group(Country_i Year)
egen impyear = group(Country_j Year)
tab(expyear), gen(expyear_)
tab(impyear), gen(impyear_)
xtreg DependentVar IndependentVar impyear_* expyear_* Year_*, robust
This code is from the practical guide to trade policy analysis https://vi.unctad.org/tpa/web/vol1/vol1home.html
I assume the regression above would be for country fixed effects, so then only time fixed effects would be:
Code:
xtreg DependentVar IndependentVar Year_*, robust
I also came across the idea of setting up the country fixed effects like this:
Code:
xtreg DependentVar IndependentVar i.Country_i##i.Country_j i.Year, fe robust
But I thought i.Var1##i.Var2 is interacting these two with each other, so I'm not sure if this code is right at all.

I thought using i.Variable automatically treats the variable as a dummy, so I assume using Year_* instead of i.Year is the same, but Year_* is the "manual" way instead of the "automatic" way. Is this assumption right?

I'm confused which regressions are "right" when using fixed effects for the gravity model and where my errors in my first assumptions are. I hope someone could clarify this.
Any help is much apprechiated, thank you very much in advance!

Graph Bar problem with allcategories and nofill option

$
0
0
Dear User,

since I can't post a .dta file, I try to explain my problem. I can't create an example dataset since that's the reason I ask my question, because I can't figure out why Stata reacts the way it reacts with my data.

My dataset consists of 3 variables: age group, categories (which has 12 categories cat1 to cat12, coded by the numbers 180 to 200) and a string variable for departments, called dep. The dep variable looks like this "#B#Y#aa#aa#aa#aa#aa#aa#" and is coded that way for some reasons.

Since I want to keep all categories shown in the graph (because of the same color), I used 2 options for my stacked bar chart: allcategories and nofill. This is the first graph I create:

Code:
global options = "stack asyvars percent allcategories nofill"
graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
I uploaded the graph as "correct1.png". So everything is fine with the graph. Not I try to create the next graph:

Code:
graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
This graph is "wrong1a.png" in the attachments. There is an empty space on the right side of the graph wich I expected not to be there. I used a tabulate command
Code:
tab agegrp5 categories if categories < 190 & strmatch(dep,"*A*"), miss
to have a look at missings, but there are none.

Now I tried the following:
Code:
keep if strmatch(dep,"*A*") == 1
drop if strmatch(dep,"*A*") & agegrp5 == 1
graph bar if categories<190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
As you can see in "wrong1b.png", now the graph is looking correct. Using the same tabulte command as above, the table looks the same, no missings and nothing that tells me why there is an empy space on the right of "wrong1a.png". So the strange thing is, when using

Code:
drop if strmatch(dep,"*A*") & agegrp5 == 2
graph bar if categories < 190 & strmatch(dep,"*A*"), over(categories) over(agegrp5) $options
The graph looks like "correct2.png" with no empty space. So I was trying to figure out the difference between my data between my 2 filters:
Code:
if strmatch(dep,"*A*") & agegrp5 == 1
if strmatch(dep,"*A*") & agegrp5 == 2
which seems to be the reason of the empty space, but there is no difference in the data I can see. So that's why I think allcategories and nofill must handle the data somehow different.

Hopy you can help me.

-Nick

Stata Date

$
0
0
I have posted a dataex for my data which quotes dates in the form YYYY.MM. I am trying to replace all the '.' with '/' so that I can convert to stata date more easily.
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(date dy) str2 country byte id
1871.01 .05855856 "US" 60
1871.02 .05777778 "US" 60
1871.03 .05639913 "US" 60
1871.04 .05485232 "US" 60
1871.05 .05349794 "US" 60
1871.06 .05394191 "US" 60
1871.07 .05496829 "US" 60
1871.08 .05427975 "US" 60
1871.09 .05371901 "US" 60
1871.1 .05664488 "US" 60
1871.11 .05603448 "US" 60
1871.12 .05485232 "US" 60
1872.01 .05417696 "US" 60
1872.02 .05465164 "US" 60
1872.03 .05357143 "US" 60
1872.04 .05276062 "US" 60
1872.05 .05341699 "US" 60
1872.06 .0545809 "US" 60
1872.07 .05554902 "US" 60
1872.08 .05688492 "US" 60
1872.09 .05858586 "US" 60
1872.1 .05901409 "US" 60
1872.11 .0599394 "US" 60
1872.12 .0591716 "US" 60
1873.01 .05919765 "US" 60
1873.02 .0592233 "US" 60
1873.03 .06017613 "US" 60
1873.04 .06150794 "US" 60
1873.05 .06188119 "US" 60
1873.06 .063253015 "US" 60
1873.07 .0638833 "US" 60
1873.08 .064386316 "US" 60
1873.09 .07026144 "US" 60
1873.1 .07756563 "US" 60
1873.11 .08106436 "US" 60
1873.12 .07466064 "US" 60
1874.01 .07081545 "US" 60
1874.02 .06875 "US" 60
1874.03 .069767445 "US" 60
1874.04 .07173913 "US" 60
1874.05 .07366072 "US" 60
1874.06 .07399103 "US" 60
1874.07 .07399103 "US" 60
1874.08 .0738255 "US" 60
1874.09 .07268722 "US" 60
1874.1 .07284768 "US" 60
1874.11 .072210066 "US" 60
1874.12 .07268722 "US" 60
1875.01 .072136566 "US" 60
1875.02 .07174393 "US" 60
1875.03 .07026144 "US" 60
1875.04 .068817206 "US" 60
1875.05 .07102908 "US" 60
1875.06 .07191781 "US" 60
1875.07 .07118451 "US" 60
1875.08 .07029478 "US" 60
1875.09 .07036613 "US" 60
1875.1 .070930235 "US" 60
1875.11 .069221966 "US" 60
1875.12 .06864989 "US" 60
1876.01 .06726457 "US" 60
1876.02 .06637168 "US" 60
1876.03 .06651885 "US" 60
1876.04 .06912442 "US" 60
1876.05 .07177033 "US" 60
1876.06 .072289154 "US" 60
1876.07 .07317073 "US" 60
1876.08 .07633588 "US" 60
1876.09 .0813008 "US" 60
1876.1 .08174387 "US" 60
1876.11 .08333334 "US" 60
1876.12 .08379889 "US" 60
1877.01 .0819155 "US" 60
1877.02 .08434132 "US" 60
1877.03 .08596215 "US" 60
1877.04 .08955783 "US" 60
1877.05 .08646259 "US" 60
1877.06 .0897436 "US" 60
1877.07 .08273684 "US" 60
1877.08 .07432787 "US" 60
1877.09 .06712963 "US" 60
1877.1 .06293052 "US" 60
1877.11 .06110429 "US" 60
1877.12 .05846154 "US" 60
1878.01 .05821538 "US" 60
1878.02 .05921384 "US" 60
1878.03 .05787037 "US" 60
1878.04 .05606607 "US" 60
1878.05 .05562874 "US" 60
1878.06 .0542522 "US" 60
1878.07 .05293103 "US" 60
1878.08 .05313044 "US" 60
1878.09 .05184659 "US" 60
1878.1 .05221264 "US" 60
1878.11 .05210375 "US" 60
1878.12 .05217391 "US" 60
1879.01 .05075419 "US" 60
1879.02 .04940701 "US" 60
1879.03 .05068493 "US" 60
1879.04 .04952255 "US" 60
end
[/CODE]

I tried a simple code:
gen date2=subinstr(date, ".", "/", .)
drop date
rename date2 date

However I am getting a mistype error for the first line. I don't think there is a mistake with the code so any ideas on what is causing the mistype error?

Interpreting margins results for a mlogit regression with variable of interest in log

$
0
0
Hello everyone

This was a long title, but it summarizes well my issue.
I ran a mlogit regression with 3 outcomes, following by the calculation of the marginal effects, such as:

mlogit Y X_ln $controls, robust
est sto A

forval i = 1/3 {
est res A
margins, dydx(X_ln) pr(out(`i')) post vce(unconditional)
est sto A`i'
}

This gives me the marginal effects of my variable of interest for the 3 possible outcomes. However, I am not sure how to interpret the impact of a variable X in log, on a dummy variable Y. Usually, it should be interpreted as "If we increase X by one percent, we expect Y to increase by (β/100) units of Y." But in this case I am not sure it really makes sense.

What I want to find at the end is the marginal effect of X on Y, not of X_log on Y.

Thanks in advance for your help

reformat (destring) var question

$
0
0
Hi Hi, I am relatively new to stata and want to reformat a variable.

the var is named p3_start_TS,
and it is a string and looks like this: 26-10-2018 10:08:59

I want to format it to a numeric var with the following format: format %tdDD/NN/CCYY p3_start_TS.

but I just cant seem to get the code right.

thanks!

Two-Stage Least Squares with cross-section weights and adjusted-R2

$
0
0
Hi!
I am currently analysing daily yield spreads of the euro-area countries over a 10-year period. I have an unbalanced panel data (N=10 and T=3.717) characterized by heteroscedasticity, serial correlation, cross-sectional correlation, and endogeneity.

Yield spreads are the dependent variable (yield).

As regressors I use the lagged yield spread (l.yield) (endogenous variable) and other three exogenous variables bid_askspread cds_spread swap_spread. The model also includes country-specific fixed effect.

In order to estimate the model, I use Two-Stage Least Squares (2SLS) and I use as Instrumental Variables the second and the third lag of the dependent variable: l(2/3).yield, and the first three lags of all independent variables: l(1/3).bid_askspread l(1/3).cds_spread l(1/3).swap_spread.

The code that I run in Stata is the following:

Code:
xtivreg yield bid_askspread cds_spread swap_spread (l.yield=l(2/3).yield l(1/3).bid_askspread l(1/3).cds_spread l(1/3).swap_spread ), fe vce (cluster country)
R2 obtained:
Within: 0.9984
Between: 1.0000
Overall: 0.9989

Some academic papers show the adjusted-R2, but Stata does give this information after running xtivreg. Is there another Stata command that gives this result?
Should R2 be lower? Do these high values of R2 mean that there is something wrong in the model implemented?
I have to run 2SLS with cross-section weights in order to account for cross-sectional heteroscedasticity, therefore I tried to generate the optimal weighting matrix that is proportional to the inverse of the covariance matrix of the sample moments, meaning that sample moments with a small variance get more weights than those with larger variance, but I have not found a command that enables to get this matrix.
Using FGLS and excluding the lagged yield spread I get FGLS with cross-section weights using this code:

Code:
xtreg yield bid_askspread cds_spread swap_spread, fe vce(cluster c)
predict e
gen logesq = ln(e*e)
reg logesq bid_askspread cds_spread swap_spread
predict esqhat, xb
gen omega = exp(esqhat)
gen w = (1/omega)^0.5
gen wyield=w* yield
gen wbidask=w* bid_askspread
gen wcds=w* cds_spread
gen wswap=w* swap_spread
xtreg wyield wbidask wcds wswap w, fe  vce(cluster c)
Is there anything similar to this code that I have to use with the xtivreg command?

Thank you in advance for any clarification

Summing or combining duplicate observations

$
0
0
Hello all,

I would like to ask how to combine/sum up data from duplicate observations. In the below data example, I would like to combine drug dose (dose) for each individual (id) who was prescribed "drug H" for multiple times.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double(id dose) long act_n
 108  50 64
 108  50 64
 108  50 64
 108  50 64
 108 100 64
 240  50 64
 240  50 64
 240  50 64
 240  50 64
 240  50 64
 240  50 64
 240  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 347  50 64
 555  50 64
 555  50 64
 555  50 64
 555  50 64
 555  50 64
 555  50 64
 555  50 64
 555  50 64
 589  50 64
 589  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
 996  50 64
1324  50 64
1324  50 64
1324  50 64
1324  50 64
1324  50 64
1324  50 64
1324  50 64
1324  50 64
1351  50 64
1632 100 64
1877 100 64
2541  50 64
2541  50 64
2541  50 64
2541  50 64
2541  50 64
2541  50 64
2541  50 64
2664  50 64
3045  50 64
3045  50 64
3045  50 64
3045  50 64
3045  50 64
3951  50 64
4272 100 64
4624  50 64
5065  50 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090 100 64
6090  50 64
end
label values act_n act_n_lb
label def act_n_lb 64 " Drug H", modify
I used
Code:
collapse (sum) dose, by (id)
but it deleted other variables (act_n).
Pls kindly suggest the command to combine the data from duplicate observations. I am using Stata 13.0 by the way.

Thank in advance.

Best Regards,
Moon Lu

Double Sorting quantiles

$
0
0
Hello,
I have got the following problem:
I am trying to sort my variable into five quintiles and within each quintile I sort another variable into five more quintiles. This results in 5x5 portfolios.
This is the dataset:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(lRsqu alphatl)
       .          .
.8492597  -.6673416
.8437587 -2.3389862
.8452843  .30016315
.8601297   .3724269
.8691546   .6786571
.8841668  2.2653832
.8876752 -2.2238657
.8821524  .55729717
.9283358    2.06477
.9538744 -3.1534085
.9451784  2.8826375
.9375255   3.282628
.9333589 -1.5626493
.9386432 -2.5049946
  .93699  2.0213053
.9399988  2.2347538
 .943158  -2.518438
.9339849  2.5404644
.9373132   .3698889
.9379639   1.414377
.9389971 -1.9083146
.9385521   1.230852
.9404954  -.7030577
.9416158   -.165016
.9440844  .12624428
.9433135  -.2099296
.9453504  -.9947472
.9473855 -1.3289968
.9482979  -2.582619
 .945869  1.3279735
.9477227  1.1662924
.9470893   2.806799
 .951561  1.9293336
.9452592   1.507581
.9410356  -1.888088
       .          .
  .84052 -4.5013776
.7640013  -1.230109
       .          .
.7953995   -1.84165
 .763701 -2.5651925
       .          .
.8122256   3.357514
.9708027  -.6237252
.9633558  -2.976884
.9508489  -1.888965
.9571319  -1.902355
.9628463   .8699767
.9585466  -.3966509
.9598147  -2.914656
.9601157  -2.044562
.9610327  -9.798227
.9082741  4.1743417
.9240623   .8981467
.9242032  4.6243277
.9056889  1.9300214
.9081386 -.04775813
.9095054   .7978305
.9122971  3.5095186
.9035737  -1.811179
.8933021   .5289839
       .          .
.9745287  -1.908935
.9745261   2.902449
.9532403 -1.4459622
.9426749  -3.514782
.9116024 -.12026531
.9143506   .3338297
.9144306   1.766378
.9275297  .05470944
.9279215  -.4787422
.9285604 -2.0074744
.9067073  3.1798935
.8383521  1.9512254
 .817727  -.1964305
.8458316   1.281453
.8398812  1.4092634
.8375641  -.8212233
.8471023  -.5335991
.8469019  1.2763717
.8445817  2.0106041
.8301534   .2856706
.8491577   .8858739
.8496809   -.438701
.8459197   .7877609
.8365584   1.344182
.8241314  -1.490751
.8412024    .894092
 .852065   1.639639
.8442533   .8743293
.8544524 -.26318347
.8795037 .030096546
 .882191  -1.814595
.8709548  -.4207301
.8442778  1.1605158
  .84082  -.9981863
.8395051 -.12342247
.8713467  -.6070057
.8986678 -1.0313703
end
I have already tried the following command
Code:
by calmt, sort: egen quantileRsqu = xtile(lRsqu), n(5)
by calmt quantileRsqu, sort: egen quantileA =xtile(alphatl), n(5)
I'm not really sure how this command works and if the results are correct.
Thanks in advance

Help on Threshold regressio

$
0
0
Good afternoon to you all
My name is David and am new to Stata. My problem is that i want to use Stata to estimate threshold level but i don't how
go about it. I try also to generate new variable from my data but it seems am not doing it right.
Please if could permit me i would like to add my data and model for you to advice me on what to do.
id year Volume Value Market Cap Inflation
1 2013 531.81 45,739,551 35408010 11.7
1 2014 553.74 79,472,245 71,419,962.81 15.5
1 2015 548.26 23,129,454 21,257,815.37 17.1
1 2016 411.2 11,835,752 10,946,399.90 17.5
1 2017 592.12 190,667,899 254,723,222.30 12.4
2 2013 1645.01 14658999 65129460 11.7
2 2014 2,228.54 6,776,134 46,640,857.62 15.5
2 2015 2,055.53 2 ,186,876 16,734,981.26 17.1
2 2016 1876.66 1,308,656 8,924,413.42 17.5
2 2017 2,228.54 3,396,754 24,642,645.00 12.4
3 2013 3032.97 20780811 3701180 11.7
3 2014 5,967.91 22,842,475 6,054,169.85 15.5
3 2015 6498.29 13,623,044 4,123,181.46 17.1
3 2016 2406.78 13,206,588 2,622,574.05 17.5
3 2017 3,850.84 15,227,384 2,055,929.71 12.4
4 2013 1285.25 11946366 56389940 11.7
4 2014 1,404.50 12,009,864 58,515,182.40 15.5
4 2015 1004.35 9 ,634,831 41,723,786.82 17.1
4 2016 943.4 8097974 28,571,555.65 17.5
4 2017 1,338.25 8,634,777 41,338,960.34 12.4


Yit =µi +β1×it h (qit < γ1) +𝛽2×it h (γ1<qitγ2) +𝛽3×it h (qitγ2) + 𝜀it

Fixed effects and interaction terms

$
0
0
Hello,
I have a little question. I am analyzing a simple fixed effects model. I have my firms classified by class (so each class is an individual id) and I have interactions between my independent variable (the exchange rate) and the dummy associated to the class. Basically I want to study how the same appreciation of the exchange rate affects the performance of the different classes. I observed that if I run my regression without interaction terms, I get reasonable results. If I run the regression without fe and only with interaction terms and I get beautiful results, super intuitive. But when I include fixed effects and interaction terms, results stop being intuitive. My question is: is there a rigorous way to check which specification is more correct? I am sorry for the stupid question, I typically do theoretical models :-)
Many thanks,

ISabella

pwcompare and effect size

$
0
0
Hello, Stata world. I'm using -pwcompare, effects- after regression. The command produces point estimates and confidence intervals, but I'm wondering if there is a way to estimate a standardized effect size such as Eta squared or Cohen's d for each contrast, which -estat esize- doesn't do.

Code:
sysuse auto
reg mpg weight i.foreign##i.rep78
pwcompare 0.foreign#rep78, effects

Thank you!

Merging dataset with non-unique variables in the master data

$
0
0
Dear all,

I am currently trying to merge two datasets.
One contains household data and the other personal data. The personal data has a household ID reference to allow for a m:1 merge.
However, since the dataset spans across many countries, I found out that the household ID is reset for each country.
To make an example, there will be a "household ID" #1 for United Kingdom that will illustrate data for the first household for UK, but so will "household #1" for Italy.
I thought there would be a "by" or similar option for merge, but I haven't seen it. Previous posts illustrate different problems to my knowledge.
Is there a way to successfully merge the datasets?
My idea was to generate a new variable with numbers from 1 to n for each household of every country to avoid repeating numbers but I wondered if there was a more elegant and safe option.
I attach a fictitious example using dataex since I am not supposed to divulge these data.
Thanks a lot.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(householdID personID) str2 country
1 1 "UK"
1 2 "UK"
2 3 "UK"
3 4 "UK"
3 5 "UK"
3 6 "UK"
1 1 "IT"
2 2 "IT"
2 3 "IT"
3 4 "IT"
4 5 "IT"
1 1 "FR"
2 2 "FR"
3 3 "FR"
4 4 "FR"
4 5 "FR"
1 1 "ES"
1 2 "ES"
1 3 "ES"
2 4 "ES"
3 5 "ES"
end

error asdoc tabdisp

$
0
0
https://drive.google.com/file/d/1iof...ew?usp=sharing

Code:
clear
input var1 str5 var2 var3 var4
1 gram 3 5
2 gram 6 5
1 maize 13 8
3 maize 3 4
2 gram 4 2
1 wheat 4 6
1 wheat 3 6
2 gram 4 4
3 wheat 5 9
1 wheat 3 6
2 wheat 1 2
2 gram 12 5
3 nuts 2 3
1 nuts 2 3.5
end

egen show1 = mean(var3), by(var1 var2)
egen show2 = total(var4), by(var1 var2)

tabdisp var2 var1, c(show?)

*Error
asdoc tabdisp var2 var1, c(show?)

Predictive Mean Matching on multiple variables

$
0
0
Hi there,

I have 3 variables in my dataset of 970 patients, for which I have missing data. Two of the variables are baseline and follow-up measurements of the same biomarker and the 3rd variable is a biomarker which is highly correlated with the previously referred to biomarker. As these biomarkers are not normally distributed, I think it would be most appropriate to use predictive mean matching to impute values for missing observations. However, my concern is whether it is appropriate to use PMM to impute on all three variables, given that it's a univariate imputation method? Any advice on the above would be greatly appreciated.

Thanks,

Claire

nobaselevels is not working

$
0
0
Hi
Please, I am using Stata 15.1. I tried to use nobaselevels in esttab to exclude base level interaction. it is not working. Any help?

eststo: quietly xtreg I L.Q CF c.L.Q#L.Dstate c.CF4#L.Dstate L.Dstate L.logTA L.LEV L.cash_TA i.year , fe vce(cluster code)
local todrop *year
esttab using "C:\Users\tables\state12.tex", varwidth(20) label replace booktabs se star(* 0.10 ** 0.05 *** 0.01) ar2 drop(`todrop') nobaselevels interaction(" $\times$ ")style(tex) ///


where Dstate is a dummy for state ownership

Thanks

Generalized empirical likelihood

$
0
0
Hello,
I was trying to estimate a GMM model for panel data. I know about xtabond2 and xtivreg2.
However, I was reading about GMM, and there is a lot of theoretical attention to the bias of GMM two-step estimators. The Generalized empirical likelihood (GEL)(Smith (1997) seem to have a smaller bias in the presence of weak instruments, and Newey Windmeijer 2009 have developed a new "sandwich" variance estimator that corrects for the fact that GEL standard errors tend to be too small.

I was wondering whether there is any rutine, user written program or implementation that I can use in stata to calculate the GEL estimator with Newey Windmeijer 2009 standard errors.

Thanks a lot for your help

regexm not recognizing characters copy-based from browse window

$
0
0
Hi Statalist,

I have had an admittedly minor but frustrating issue happen in several different contexts, and I beginning to think I am missing something obvious.

First, I import the data:

Code:
import delimited using "$root/EDULIT_DS_18092019122536422.csv", clear encoding("UTF-8")
The dataset that looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str109 indicator str52 country int year float value
"Government expenditure on pre-primary education, US$ (millions)"                                               "Afghanistan" 2013         .
"Government expenditure on education, US$ (millions)"                                                           "Afghanistan" 2013  710.2747
"Government expenditure on primary education, US$ (millions)"                                                   "Afghanistan" 2013  426.2217
"Government expenditure on lower secondary education, US$ (millions)"                                           "Afghanistan" 2013   116.178
"Government expenditure on upper secondary education, US$ (millions)"                                           "Afghanistan" 2013  66.92618
"Government expenditure on secondary education, US$ (millions)"                                                 "Afghanistan" 2013 183.10417
"Government expenditure on education not specified by level, US$ (millions)"                                    "Afghanistan" 2013         .
"Government expenditure on secondary and post-secondary non-tertiary vocational education only, US$ (millions)" "Afghanistan" 2013  21.40801
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Afghanistan" 2013  17.44303
"Government expenditure on tertiary education, US$ (millions)"                                                  "Afghanistan" 2013  83.50579
"Government expenditure on education, US$ (millions)"                                                           "Afghanistan" 2014   756.962
"Government expenditure on secondary education, US$ (millions)"                                                 "Afghanistan" 2014 192.20827
"Government expenditure on education not specified by level, US$ (millions)"                                    "Afghanistan" 2014         .
"Government expenditure on tertiary education, US$ (millions)"                                                  "Afghanistan" 2014  93.94871
"Government expenditure on upper secondary education, US$ (millions)"                                           "Afghanistan" 2014   70.2538
"Government expenditure on secondary and post-secondary non-tertiary vocational education only, US$ (millions)" "Afghanistan" 2014  27.67649
"Government expenditure on primary education, US$ (millions)"                                                   "Afghanistan" 2014  447.4138
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Afghanistan" 2014  23.39132
"Government expenditure on lower secondary education, US$ (millions)"                                           "Afghanistan" 2014 121.95446
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Afghanistan" 2015  19.40793
"Government expenditure on primary education, US$ (millions)"                                                   "Afghanistan" 2015  367.4638
"Government expenditure on upper secondary education, US$ (millions)"                                           "Afghanistan" 2015  57.69989
"Government expenditure on education, US$ (millions)"                                                           "Afghanistan" 2015  648.1357
"Government expenditure on secondary and post-secondary non-tertiary vocational education only, US$ (millions)" "Afghanistan" 2015  22.88935
"Government expenditure on lower secondary education, US$ (millions)"                                           "Afghanistan" 2015 100.16199
"Government expenditure on tertiary education, US$ (millions)"                                                  "Afghanistan" 2015  103.4022
"Government expenditure on pre-primary education, US$ (millions)"                                               "Afghanistan" 2015         .
"Government expenditure on education not specified by level, US$ (millions)"                                    "Afghanistan" 2015         .
"Government expenditure on secondary education, US$ (millions)"                                                 "Afghanistan" 2015  157.8619
"Government expenditure on secondary and post-secondary non-tertiary vocational education only, US$ (millions)" "Afghanistan" 2016  22.57008
"Government expenditure on lower secondary education, US$ (millions)"                                           "Afghanistan" 2016 117.33885
"Government expenditure on education not specified by level, US$ (millions)"                                    "Afghanistan" 2016         .
"Government expenditure on secondary education, US$ (millions)"                                                 "Afghanistan" 2016  175.8388
"Government expenditure on upper secondary education, US$ (millions)"                                           "Afghanistan" 2016  58.49995
"Government expenditure on pre-primary education, US$ (millions)"                                               "Afghanistan" 2016         .
"Government expenditure on primary education, US$ (millions)"                                                   "Afghanistan" 2016  348.7321
"Government expenditure on education, US$ (millions)"                                                           "Afghanistan" 2016  805.3478
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Afghanistan" 2016  23.93759
"Government expenditure on upper secondary education, US$ (millions)"                                           "Afghanistan" 2017  58.70909
"Government expenditure on secondary and post-secondary non-tertiary vocational education only, US$ (millions)" "Afghanistan" 2017  13.97529
"Government expenditure on secondary education, US$ (millions)"                                                 "Afghanistan" 2017 176.53076
"Government expenditure on pre-primary education, US$ (millions)"                                               "Afghanistan" 2017         .
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Afghanistan" 2017  15.08166
"Government expenditure on lower secondary education, US$ (millions)"                                           "Afghanistan" 2017 117.82167
"Government expenditure on primary education, US$ (millions)"                                                   "Afghanistan" 2017  350.5486
"Government expenditure on education, US$ (millions)"                                                           "Afghanistan" 2017  793.2651
"Government expenditure on education not specified by level, US$ (millions)"                                    "Afghanistan" 2017         .
"Government expenditure on secondary education, US$ (millions)"                                                 "Albania"     2013  89.67648
"Government expenditure on education not specified by level, US$ (millions)"                                    "Albania"     2013   5.89411
"Government expenditure on upper secondary education, US$ (millions)"                                           "Albania"     2013  27.32272
"Government expenditure on tertiary education, US$ (millions)"                                                  "Albania"     2013  99.16112
"Government expenditure on lower secondary education, US$ (millions)"                                           "Albania"     2013  62.35376
"Government expenditure on education, US$ (millions)"                                                           "Albania"     2013  452.1908
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Albania"     2013         .
"Government expenditure on education not specified by level, US$ (millions)"                                    "Albania"     2015   1.94695
"Government expenditure on tertiary education, US$ (millions)"                                                  "Albania"     2015  82.82124
"Government expenditure on upper secondary education, US$ (millions)"                                           "Albania"     2015  17.33905
"Government expenditure on education, US$ (millions)"                                                           "Albania"     2015  391.4789
"Government expenditure on lower secondary education, US$ (millions)"                                           "Albania"     2015  67.14867
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Albania"     2015         .
"Government expenditure on primary education, US$ (millions)"                                                   "Albania"     2015 222.23058
"Government expenditure on secondary education, US$ (millions)"                                                 "Albania"     2015  84.48763
"Government expenditure on tertiary education, US$ (millions)"                                                  "Albania"     2016  89.75494
"Government expenditure on education, US$ (millions)"                                                           "Albania"     2016   469.957
"Government expenditure on secondary education, US$ (millions)"                                                 "Albania"     2016  119.2252
"Government expenditure on education not specified by level, US$ (millions)"                                    "Albania"     2016   7.65934
"Government expenditure on upper secondary education, US$ (millions)"                                           "Albania"     2016  32.99036
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Albania"     2016         .
"Government expenditure on lower secondary education, US$ (millions)"                                           "Albania"     2016  86.23484
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Algeria"     2014         .
"Government expenditure on education not specified by level, US$ (millions)"                                    "Andorra"     2013   7.85449
"Government expenditure on lower secondary education, US$ (millions)"                                           "Andorra"     2013  23.04739
"Government expenditure on primary education, US$ (millions)"                                                   "Andorra"     2013  25.71746
"Government expenditure on secondary education, US$ (millions)"                                                 "Andorra"     2013   28.2005
"Government expenditure on pre-primary education, US$ (millions)"                                               "Andorra"     2013   14.5636
"Government expenditure on tertiary education, US$ (millions)"                                                  "Andorra"     2013   3.67144
"Government expenditure on upper secondary education, US$ (millions)"                                           "Andorra"     2013    5.1531
"Government expenditure on education, US$ (millions)"                                                           "Andorra"     2013  80.00748
"Government expenditure on lower secondary education, US$ (millions)"                                           "Andorra"     2014  15.36607
"Government expenditure on education, US$ (millions)"                                                           "Andorra"     2014  100.4487
"Government expenditure on pre-primary education, US$ (millions)"                                               "Andorra"     2014  13.87391
"Government expenditure on tertiary education, US$ (millions)"                                                  "Andorra"     2014    6.1028
"Government expenditure on upper secondary education, US$ (millions)"                                           "Andorra"     2014    5.2323
"Government expenditure on education not specified by level, US$ (millions)"                                    "Andorra"     2014  37.48375
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Andorra"     2014         .
"Government expenditure on secondary education, US$ (millions)"                                                 "Andorra"     2014  20.59837
"Government expenditure on primary education, US$ (millions)"                                                   "Andorra"     2014  22.38988
"Government expenditure on pre-primary education, US$ (millions)"                                               "Andorra"     2015  12.05604
"Government expenditure on upper secondary education, US$ (millions)"                                           "Andorra"     2015   7.05772
"Government expenditure on tertiary education, US$ (millions)"                                                  "Andorra"     2015   5.00818
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Andorra"     2015    .09704
"Government expenditure on primary education, US$ (millions)"                                                   "Andorra"     2015  20.19416
"Government expenditure on education, US$ (millions)"                                                           "Andorra"     2015  91.47684
"Government expenditure on education not specified by level, US$ (millions)"                                    "Andorra"     2015  31.33137
"Government expenditure on lower secondary education, US$ (millions)"                                           "Andorra"     2015  15.73232
"Government expenditure on secondary education, US$ (millions)"                                                 "Andorra"     2015  22.79003
"Government expenditure on upper secondary education, US$ (millions)"                                           "Andorra"     2016   7.22343
"Government expenditure on post-secondary non-tertiary education, US$ (millions)"                               "Andorra"     2016    .20803
"Government expenditure on education, US$ (millions)"                                                           "Andorra"     2016  93.70532
"Government expenditure on secondary education, US$ (millions)"                                                 "Andorra"     2016   22.4614
end
I copy-paste an observation from the indicator variable in the browse window, isolate the "US$ (millions)", attempt to assert, and receive the following error:

Code:
. assert regexm(indicator, "US$ (millions)")
4,294 contradictions in 4,294 observations
assertion is false
r(9);
Notice that I have contradictions for every single observation, meaning that the copy-pasted string is not recognized even once.

I thought maybe this was a unicode issue, since I am importing the csv at the top using UTF-8 encoding, but I tried ustrregexm to no avail:

Code:
. assert ustrregexm(indicator, "US$ (millions)")
4,294 contradictions in 4,294 observations
assertion is false
r(9);
I am a little perplexed. How is this possible / what am I missing here? Is there a problem with the odd characters "$" or "(" in my string?

Thanks,

Julian

tabulate average values

$
0
0
Is there any command that will tabulate average values of another variable for each value of a different variable? I know reg does provide but I want something that also shows the number of obs used to calculate the average etc in the same row.

ie if var1 has three values: 1, 2, and 3

then some command that will tabulate the average value of var2 for each value of var1.



thanks!
Donovan

Adding macros into matrix after -lincomestadd- and -reghdfe-

$
0
0
Hi

Im using Stata MP 15.0 Windows 10 (64 bits) with -lincomestadd- and -reghdfe-

Code:
.which lincomestadd
M:\Ado\plus\l\lincomestadd.ado

.which reghdfe
M:\Ado\plus\r\reghdfe.ado
*! version 5.7.2 29jul2019

I generated macros and scalars from linear combinations tested using -lincomestadd-, and attached them to different regressions using -reghdfe-. I can clearly see that scalars and macros from these linear combinations have been added to the stored high density fixed effects regressions. So far, so good. However, I'm having problems when adding some of the macros generated by -lincomestadd- into a matrix. Suppose a have a matrix 2x2, where each column corresponds to models 1 and 2, while row 1 and row 2 corresponds to their tested combination and s.e. respectively. For doing that I'm generating one matrix, then calling the estimates stored by using -estimates restore- and then adding the scalars into the matrix.

Code:
. webuse union, clear
(NLS Women 14-24 in 1968)

. eststo m1: quietly reghdfe age c.union##c.black if south == 0, absorb(year) vce(robust)
. lincomestadd _b[union] + _b[black] + _b[c.union#c.black] , statname(ex)

 ( 1)  union + black + c.union#c.black = 0

------------------------------------------------------------------------------
         age |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |  -.0682821   .0909671    -0.75   0.453    -.2465884    .1100242
------------------------------------------------------------------------------

added macro:
                e(exb) : "-0.068"

added macro:
               e(exse) : "(0.091)"

added macro:
                e(ext) : "-0.751"

added scalar:
            e(exb_num) =  -.0682821

added scalar:
           e(exse_num) =  .09096709

added scalar:
            e(ext_num) =  -.75062429

. eststo m2: quietly reghdfe age c.union##c.black if south == 1, absorb(year) vce(robust)
. lincomestadd _b[union] + _b[black] + _b[c.union#c.black] , statname(ex)

 ( 1)  union + black + c.union#c.black = 0

------------------------------------------------------------------------------
         age |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         (1) |  -.1811774   .0992281    -1.83   0.068    -.3756827    .0133278
------------------------------------------------------------------------------

added macro:
                e(exb) : "-0.181*"

added macro:
               e(exse) : "(0.099)"

added macro:
                e(ext) : "-1.826"

added scalar:
            e(exb_num) =  -.18117743

added scalar:
           e(exse_num) =  .09922808

added scalar:
            e(ext_num) =  -1.8258685


. matrix mat = J(2,2,.)

. forvalues i = 1/2 {
  2. estimates restore m`i'
  3. matrix mat[1,`i'] = e(exb_num)
  4. matrix mat[2,`i'] = e(exse_num)
  5. }
(results m1 are active now)
(results m2 are active now)

. matlist mat

             |     c1         c2
-------------+----------------------
          r1 | -.0682821  -.1811774
          r2 |  .0909671   .0992281
However, because I want to preserve the format from the macros (stars for coefficients and parenthesis for s.e.) I would prefer to use them instead scalars. Something visually like this:


Code:
             |     c1         c2
-------------+----------------------
          r1 |  -0.068     0.181*
          r2 |  (0.091)   (0.099)
What I tried to do was to save the macros as "strings" or local values, but something is not working, it says value is not found:
(added -display- just to double check the figures and format were correct)

Code:
. matrix mat = J(2,2,.)
. forvalues i = 1/2 {
  2. estimates restore m`i'
  3. local ex_coef : display e(exb)
  4. display "`ex_coef'"
  5. local ex_se : display e(exse)
  6. display "`ex_se'"
  7. matrix mat[1,`i'] = `ex_coef'
  8. matrix mat[2,`i'] = `ex_se'
  9. }
(results m1 are active now)
-0.068
(0.091)
(results m2 are active now)
-0.181*
(0.099)
0.181* not found
r(111);

Any help will be appreciated
Roberto
Viewing all 65099 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>