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

Error in converting time (hourly) variable

$
0
0
Hi. I have hourly level data with the format, "2010123123" representing "23:00 Dec 31, 2010". I can convert it into time variable by using "double" but there is a problem for some observations. The data show "00:00 Jan 1, 2011" as 2010123124 and Stata does not automatically change it to the midnight next day and generate an empty cell, shown as below. I would really appreciate it if you could help me to correctly convert it into the next day format. Thank you very much!

Array

Adjusted variable and deviation

$
0
0
Hi,

I want to generate a new variable (RC) with the sum of industry-year (-Risky_Ind- and -year-) adjusted -INV- and -REC- as a percentage of -TA-, and expressed as deviation from the corresponding industry-year mean.

I would be grateful if you could help me with generating the new variable.

Note: IS is the company identifier.

example:

. dataex IS INV REC TA year risky_ind in 1/50

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str11 IS double(INV REC TA) int year float risky_ind
"IQ1001135"     2.20403  2.52538   42.87435 2013 0
"IQ1001135"     2.83681   3.1106   24.37639 2014 0
"IQ10038253"   10.03707  9.87853   67.32937 2017 0
"IQ100475337" 140.42434 64.60702 1320.80513 2013 0
"IQ100475337"  95.74748 65.44843  857.81385 2014 0
"IQ100475337"  53.54069  52.1743  574.70545 2015 0
"IQ100475337"  58.86901  38.4869  501.58682 2016 0
"IQ100475337"  46.88747 37.78913  427.04402 2017 0
"IQ100475337"  17.20336 47.58633  450.97572 2018 0
"IQ10059716"   13.97032  2.20655   64.91229 2014 0
"IQ10059716"   12.58804  1.39677   79.95269 2015 0
"IQ10059716"   13.46922  1.33011   71.59447 2016 0
"IQ10059716"   15.93507  2.52412   76.18798 2017 0
"IQ10059716"   16.80082  1.94413   83.10289 2018 0
"IQ100601859"  59.32227 15.65512  200.16184 2013 0
"IQ100601859"  69.46581   9.0277  250.01989 2014 0
"IQ100601859"   76.5801 13.21964  289.17414 2015 0
"IQ100601859"  57.17937  9.38205  265.69254 2016 0
"IQ100601859"  45.53861  6.08402  329.99212 2017 0
"IQ100601859"  41.12032  5.39557  338.10262 2018 0
"IQ10063218"     .10101   .55322   16.63223 2016 0
"IQ10063218"     .13055  1.21617   18.80271 2017 0
"IQ10063218"     .09417  1.42922   15.64643 2018 0
"IQ1007880"        44.6    175.1     3016.5 2014 0
"IQ1007880"        39.5    168.1     2765.1 2015 0
"IQ102377327"    16.528    7.584     63.839 2013 0
"IQ102377327"    12.146    3.755     40.429 2014 0
"IQ102377327"    10.037    3.182     29.465 2015 0
"IQ102377327"    12.977    3.546     35.056 2016 0
"IQ102377327"    19.175    3.427     66.001 2018 0
"IQ1027520"      .13204 39.70413  174.29746 2013 1
"IQ1027520"      .10263 40.96519  164.38773 2014 1
"IQ1027520"       .1358  47.1315  206.26628 2015 1
"IQ1027520"       .1389 44.97404   207.2047 2016 1
"IQ1027520"      .10174 54.73586  267.06623 2017 1
"IQ1027520"      .09828 58.96796  302.21079 2018 1
"IQ10332217"    3.54973    3.542   10.19086 2013 0
"IQ10332217"     4.0283   3.5752   11.44259 2014 0
"IQ10332217"    4.58241  3.68841   12.71978 2015 0
"IQ10332217"    5.49894   4.2628   14.14477 2016 0
"IQ10332217"    4.99721  4.58772   15.03865 2017 0
"IQ10332217"    4.97193  4.85585   16.30446 2018 0
"IQ1034090"           .    348.4     1094.6 2013 0
"IQ1034090"           .    326.1     1031.5 2014 0
"IQ1034090"           .    300.8     1086.3 2015 0
"IQ1034090"           .    339.8     1074.5 2016 0
"IQ1034090"           .    364.9     1149.9 2017 0
"IQ1034090"           .    335.4     1197.6 2018 0
"IQ1034269"       2.198    1.781     18.498 2013 0
"IQ1034269"        .067     .465       7.56 2014 0
end
------------------ copy up to and including the previous line ------------------

Listed 50 out of 4887 observations

.



Best,
Mahmoud

Suest - Can I cluster just 1 model?

$
0
0
Dear all,

I'm trying to compare the coefficients of an OLS regression with a multilevel regression. I tried to use the Hausman command but got an error saying that
Code:
 
 "model fitted on these data fails to meet the asymptotic assumptions of the Hausman test; see suest for a generalized test"
I'm trying to use the Suest command as a proper solution, but this command doesn't work after Mixed command. I understand that there's an option to use
Code:
vce(cluster clustervar)
in order to cluster 1-level models and with that use this command for mixed models.

However, in my case there's only one model with clustering (the other is just a normal linear regression), so if I try this syntax -

Code:
regress sqrt_Relative_time_days White Hispanic Other Age Sex i.Seriousness_of_crime_7 Death_Penalty i.year_of_conviction_groups

estimates store fixed


mixed sqrt_Relative_time_days White Hispanic Other Age Sex i.Seriousness_of_crime_7 Death_Penalty i.year_of_conviction_groups  || states_combined:

estimates store random

suest fixed random, vce(cluster clustervar)
the command create two identical clustered regression, where I want just the second one to be clustered (the model I call "random").

Is there a way to cluster just 1 model in the suest command?

Thanks!
Eran

Dummy Variable??

$
0
0
Hi All,

I have tried to find this answer in the forum but cant seem to.
I have a set of panel data for 15 countries over 10 years and want to create a dummy based on per capita income levels, per year but split into 3. Hope this makes sense
Usually with cross section i would first create the median income per year (as i want equal observations in each half(75))

egen MEDINCOME=median(income), by (year)

then gen dummy = income>MEDINCOME

However, I would like to have 3 splits instead of just two, eg 50 observations in each to get the equivalent of high income, middle income and lower income.

Is this possible?

Thank you

Safia

event study - eventstudy2

$
0
0
I am a postgraduate student writing my thesis. I am somewhat a novice in the field I have chosen to study, however this has undoubtedly broadened my horizons. I am attempting to evaluate the impact of FOMC news on the dow jones industrial average. Please excuse me for resorting to the forum the for help but I am getting quite confused with all the material I have seen on event studies and would really appreciate a specific direction at this stage.

My study: I have two periods that I will evaluate; 2008 - 2013 and then 2013 - 2018. I have a total of 63 events - 23 in the 2008 - 2013 period and 40 in the 2013 - 2018 period - and I am using open/close data. Due to data access, I was unable to obtain intraday data (for less than £1500) but I feel using the open/close data will enable me to provide a broad view and still comment on any pre-announcement drift and lasting effects of FOMC news (thus commenting on efficient market theory). To that end, I would like to evaluate the way in which the Dow anticipates FOMC news 3 days prior to the announcement and the way in which news is incorporated, 3 days after the event.

I have used Stata for past projects, unrelated to finance and feel its use would will be quicker than attempting to evaluate each event in Excel, further I would like to make use of the estout or outreg2 for output tables. I also had the idea to evaluate the effects of unscheduled meetings - so effectively, another set of events. I considered using dummies/ changing (d.var d2.var etc) for x days – leading and lagging (1, 2,3, 4 ) to see if there is any reaction and whether it is more dramatic or not of the scheduled meetings. I suppose they would be in reaction to shocks and a such not working in the same way as the schedule ones. I have done something similar on a project that was not finance related so excuse the novice approach but is this something that could still be done using for example, eventstudy2?

The majority of event studies I have seen appear to evaluate a stock against an index (eg. apple against the S&P 500 is very common) to thus estimate normal performance, abnormal and cumulative abnormal returns, as well as being able to test for significance. Is it possible to conduct an event study with just the Dow Jones?

If all seems feasible, does anyone have direction of how I could go about starting my study using eventstudy2. There is usually an abundance of information regarding the stata packages but there seems to be little on eventstudy2.

I have attached a dataset which I have prepared for Stata import.

Thanks in advance.

Age and Gender

$
0
0
Bonjour,

First and foremost, I have to warn you that Im such a beginner on STATA & statistics overall ...
But with regards to my master thesis on fashion windows displays & consumer behavior, I had to do statistics analyses !
Anyway, Im facing now the issue of including gender & age, as covariates/moderator variables of the model.

gender: male (116), female (97), non-binary (27)
age: 18-24 (195), 25-34 (27), 35-44 (7), 45-60+ (11)
In total 240 participants, but the sample sizes are different! I think it is a problem.

I tried to code both as dummy variables, but received the message "no observations".

I want to study if including genders identities influence Entry Intention (Y outcome variable) regarding f4 different Fashion Windows Displays (independent variables: X1Mannequins X2PunchyWarmColors X3InteractiveTechnology X4CreativeDesign)
And I want to know if age has an impact on the attraction towards technology-based window.

- maybe: dummy variables are not the solution?
- others models should be used like: a binary response model?
- maybe ANOVA? by separating the population using a median split?

I already reg per gender & the three models are significant p-value <0,05, R²<1.
Also, F-Test is OK.
VIF: checked as well.

I hope that I have expressed myself correctly.
I include here my Excel file.

Brgrds,
Isabelle Deschamps

Misstable

$
0
0
Hello,

Looking to do misstable summarize. I have a variable split into cases and controls. Then I have another variable that I want to see how many missing values there are. But I want to know how many missing values there are for the cases and controls. Is there a code for this so that I don't just see the total number of missing values but rather have it split via another variable?

Thanks

Generating mean returns, based on xtile returns

$
0
0
Hi comminuty,

I seem to have problems with calculating mean returns (ret_sup in my data). My dataset has weekly obeservations for returns(customer en supplier). The lagged customer returns are split into quintiles of 5 with xtile. Based on the rank of the lagged customer returns, I want to calculate the weekly return of the associated supplier returns per quintile.

I used the following codes, but when I manually calculate the returns with excel for double checking, it doesnt give me the same results:
Code:
by stic ctic: gen L_ret= ret_cus[_n-1]
egen retQ = xtile(L_ret), by( week_id ) nq(5)
by week_id : egen retQ1=mean(ret_cus) if  retQ ==1
by week_id : egen retQ2=mean(ret_cus) if  retQ ==2
by week_id : egen retQ3=mean(ret_cus) if  retQ ==3
by week_id : egen retQ4=mean(ret_cus) if  retQ ==4
by week_id : egen retQ5=mean(ret_cus) if  retQ ==5
My dataex exactly consists of 1 week of paneldata.
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8(stic ctic) float(week_id ret_sup ret_cus L_ret retQ retQ1 retQ2 retQ3 retQ4 retQ5)
"PCZ"   "CWG"   1926  .023622047  .069767445   .01775148 3         .         . .0150178 .           .
"CPCI"  "SNE"   1926  .067307696   .02152642   .02152642 3         .         . .0150178 .           .
"CSDS"  "GND"   1926  -.11594203  -.06666667      -.0625 1 .05393586         .        . .           .
"PGEX"  "FTR"   1926   .05633803         .03 .0033444816 2         . .03446858        . .           .
"HMTT"  "IOM"   1926   .04918033    .1119403  -.02189781 1 .05393586         .        . .           .
"SRI"   "GM"    1926           .  .016393442  .029535865 3         .         . .0150178 .           .
"VICL"  "RPR"   1926 -.007352941  .011666667           0 2         . .03446858        . .           .
"KOPN"  "ROK"   1926  -.04807692  .030674847 -.012121212 1 .05393586         .        . .           .
"MXC"   "AQP"   1926  -.06451613  .008130081 -.008064516 2         . .03446858        . .           .
"TSGI"  "NYN"   1926  -.06666667  .012562814  .015306123 3         .         . .0150178 .           .
"AKS"   "GM"    1926   .04153354  .016393442  .029535865 3         .         . .0150178 .           .
"LEA"   "GM"    1926 -.006493506  .016393442  .029535865 3         .         . .0150178 .           .
"JCI"   "GM"    1926   -.0056899  .016393442  .029535865 3         .         . .0150178 .           .
"VCOM"  "DSCP"  1926 -.014084507 -.010526316   .11111111 5         .         .        . . .0038411536
"SHLO"  "GM"    1926  .028169014  .016393442  .029535865 3         .         . .0150178 .           .
"IVAC"  "HMTT"  1926   .04635762   .04918033   .18217054 5         .         .        . . .0038411536
"CSPLF" "CWG"   1926  -.01724138  .069767445   .01775148 3         .         . .0150178 .           .
"BJICA" "DRYR"  1926   -.0825688 -.016666668 -.024390243 1 .05393586         .        . .           .
"MNR"   "AJL"   1926  -.02777778  .032786883  -.07575758 1 .05393586         .        . .           .
"ITT"   "GM"    1926  .005780347  .016393442  .029535865 3         .         . .0150178 .           .
"ALET"  "ALET"  1926   .04166667   .04166667   .04166667 5         .         .        . . .0038411536
"MCCL"  "WMX"   1926  -.08571429 -.011235955  .011363637 3         .         . .0150178 .           .
"SPTR"  "OCC"   1926   .02352941   .06498195 -.017730497 1 .05393586         .        . .           .
"LRCI"  "BKCO"  1926    .0925926   .03448276  .035714287 5         .         .        . . .0038411536
"JPMX"  "DBD"   1926           0  -.07212476           . .         .         .        . .           .
"DSPT"  "GM"    1926           0  .016393442  .029535865 3         .         . .0150178 .           .
"PRCP"  "GM"    1926 -.028368793  .016393442  .029535865 3         .         . .0150178 .           .
"CPCI"  "SNE"   1926  .067307696   .02152642  -.04307116 1 .05393586         .        . .           .
"CVTX"  "BGEN"  1926    .0877193   .15337424 -.006097561 2         . .03446858        . .           .
"PCZ"   "TRP"   1926  .023622047   .02142857  .007194245 2         . .03446858        . .           .
"CEPH"  "CHIR"  1926   .11229946    -.040625  .012658228 3         .         . .0150178 .           .
"CFCI"  "REY"   1926   .02479339   .03809524  .024390243 3         .         . .0150178 .           .
"ROG"   "AFLX"  1926 -.009090909  -.10784314   .05154639 5         .         .        . . .0038411536
"AFLX"  "SFLX"  1926  -.10784314 -.015151516  .023255814 3         .         . .0150178 .           .
"KLOC"  "CBS"   1926  -.06666667           0  .018072288 3         .         . .0150178 .           .
"HIW"   "HIW"   1926 -.003610108 -.003610108  .029739777 5         .         .        . . .0038411536
"DEFI"  "GM"    1926  -.01923077  .016393442  .029535865 3         .         . .0150178 .           .
"RGLD"  "PDG"   1926         -.1   .03030303  .012269938 3         .         . .0150178 .           .
"SIND"  "SHX"   1926   .11764706   .07692308  -.02803738 1 .05393586         .        . .           .
"STCL"  "RCII"  1926    .1935484   .02255639   .11764706 5         .         .        . . .0038411536
"STRB"  "CBS"   1926           0           0  .018072288 3         .         . .0150178 .           .
"WN"    "GM"    1926   -.3415638  .016393442  .029535865 3         .         . .0150178 .           .
"MCCL"  "MCCL"  1926  -.08571429  -.08571429   .14130434 5         .         .        . . .0038411536
"DECO"  "RBD"   1926           0   .03910615  .017045455 3         .         . .0150178 .           .
"CSYI"  "SGMA"  1926  -.01369863   .05755396  .007246377 3         .         . .0150178 .           .
"SMPS"  "GM"    1926 -.011494253  .016393442  .029535865 3         .         . .0150178 .           .
"BGG"   "ELUXY" 1926  .013812155  -.02484472   .07572383 5         .         .        . . .0038411536
"HILI"  "GM"    1926   .15789473  .016393442  .029535865 3         .         . .0150178 .           .
"ALET"  "ALET"  1926   .04166667   .04166667           0 2         . .03446858        . .           .
"NFG"   "UGI"   1926  -.02285714  .005586592           0 2         . .03446858        . .           .
"ZRAN"  "IOM"   1926   .22826087    .1119403  -.02189781 1 .05393586         .        . .           .
"SUP"   "GM"    1926 -.010869565  .016393442  .029535865 3         .         . .0150178 .           .
"GLFD"  "RPR"   1926        -.02  .011666667           0 2         . .03446858        . .           .
"TIII"  "NYN"   1926    .1122449  .012562814  .015306123 3         .         . .0150178 .           .
"CHK"   "AQP"   1926   -.1440678  .008130081 -.008064516 2         . .03446858        . .           .
"PTSI"  "GM"    1926 -.020833334  .016393442  .029535865 3         .         . .0150178 .           .
"NAII"  "AJL"   1926  -.01369863  .032786883  -.07575758 1 .05393586         .        . .           .
"SPZE"  "EIRE"  1926       .1875   .13414635  .031446543 5         .         .        . . .0038411536
"HICKA" "GM"    1926      -.0125  .016393442  .029535865 3         .         . .0150178 .           .
"ORCI"  "GM"    1926  -.03448276  .016393442  .029535865 3         .         . .0150178 .           .
"AMSC"  "CWP"   1926 -.032967035  .037037037 -.010471204 2         . .03446858        . .           .
"HAVA"  "GM"    1926         .35  .016393442  .029535865 3         .         . .0150178 .           .
"GNTX"  "GM"    1926  -.07317073  .016393442  .029535865 3         .         . .0150178 .           .
"ARRS"  "TCOMA" 1926   .07476635   .04424779  -.02586207 1 .05393586         .        . .           .
"GGNS"  "IIII"  1926  -.11764706           0 -.006993007 2         . .03446858        . .           .
"NSCC"  "OHM"   1926   .04347826 -.014492754           0 2         . .03446858        . .           .
"RGR"   "ELY"   1926  .006535948   .12820514 -.012658228 1 .05393586         .        . .           .
"IMPX"  "ROK"   1926  .071428575  .030674847 -.012121212 1 .05393586         .        . .           .
"AWRE"  "USRX"  1926   .25714287  .008561644   .06181818 5         .         .        . . .0038411536
"STRT"  "GM"    1926           0  .016393442  .029535865 3         .         . .0150178 .           .
"IMPX"  "IOM"   1926  .071428575    .1119403  -.02189781 1 .05393586         .        . .           .
"MAYS"  "FULT"  1926           0   .10843374           0 2         . .03446858        . .           .
"SWTX"  "SNE"   1926  -.05357143   .02152642  -.04307116 1 .05393586         .        . .           .
"AOS"   "YRK"   1926  -.06072874  .009433962 -.023041476 1 .05393586         .        . .           .
"LCBM"  "CHIR"  1926 -.006849315    -.040625  .012658228 3         .         . .0150178 .           .
"FSCR"  "GM"    1926  .022900764  .016393442  .029535865 3         .         . .0150178 .           .
"INVI"  "GM"    1926           0  .016393442  .029535865 3         .         . .0150178 .           .
"ORBT"  "GM"    1926    .0882353  .016393442  .029535865 3         .         . .0150178 .           .
"SPA"   "WAT"   1926  .008064516   .06521739 -.033613447 1 .05393586         .        . .           .
"NAII"  "NUS"   1926  -.01369863    -.041841  .012711864 3         .         . .0150178 .           .
"NFG"   "NUI"   1926  -.02285714           0           0 2         . .03446858        . .           .
"CTS"   "GM"    1926  .028744327  .016393442  .029535865 3         .         . .0150178 .           .
"KVHI"  "GM"    1926           0  .016393442  .029535865 3         .         . .0150178 .           .
"WALB"  "GM"    1926           0  .016393442  .029535865 3         .         . .0150178 .           .
"SEC"   "MCD"   1926  .037037037   .04519774           0 2         . .03446858        . .           .
"DASTY" "DASTY" 1926 -.011961723 -.011961723   .14520548 5         .         .        . . .0038411536
"DRTE"  "RPR"   1926      -.0625  .011666667           0 2         . .03446858        . .           .
"PMD"   "GM"    1926   .02654867  .016393442  .029535865 3         .         . .0150178 .           .
"KRT"   "HCDV"  1926  .014492754           0 -.032967035 1 .05393586         .        . .           .
"ASI"   "ASI"   1926   .29801324   .29801324  -.01948052 1 .05393586         .        . .           .
"PAR"   "MCD"   1926   .14049587   .04519774           0 2         . .03446858        . .           .
"PDKL"  "COGE"  1926 -.023809524   .09574468 -.005291005 2         . .03446858        . .           .
"PSDS"  "DRI"   1926   .10204082  -.03076923 -.029850746 1 .05393586         .        . .           .
"WCSTF" "GM"    1926  -.01599016  .016393442  .029535865 3         .         . .0150178 .           .
"BWA"   "GM"    1926   .04140127  .016393442  .029535865 3         .         . .0150178 .           .
end
format %tw week_id
Thanks in advance, help would be appreciated here.

Geonear producing unstable results

$
0
0
I'm trying to use geonear to identify the nearest neighbors within a dataset at the household-day level.

I've got longitude with a level of precision ranging between the 4-6 decimal place. I've got latitude to the 6th decimal place always.

I ran a do-file, which produces the six nearest neighbors, four times. The first two times I ran it, they produced the same results. The second two times I ran it they varied in the final neighbor identification.

Is there a place where I can expect this type of variation in output to occur? Is it less likely if I specify a within()?

For what it is worth, here is my code.

Code:
preserve

rename hhd_id nbor_index
sort nbor_index, stable
tempfile nbor
save `nbor'

restore

sort hhd_id, stable
geonear hhd_id lat lon using `nbor', n(nbor_index lat lon) ign wide near(6)

Redistributing a Group's percentiles in panel data

$
0
0
Hi, this is my first post in Statalist and I'm hoping you can help me.

I am using a panel data set with really good coverage 2001-2018, however, the DTI for 1999 and 2000 is shaky at best for a specific group (where DTI drops to 50 obs where there should be 10,000.) We used multiple imputations as a fix but when compared to a benchmark, they fell 7 points lower than expected DTI's.

I have a benchmark for the 10th, 25th, 50th, 75th, and 90th percentiles from a reliable source for 1999 and 2000 with a total count for the year.

I have never created weights before/ have barely used them.
But should I make sample weights for my specific group for 2000, or create buckets?

I know this is vague, but I'm not sure what information would help for clarity.

Best and Thanks,
Sian

Problem with estimation of coefficient in panel regression

$
0
0
My aim is to estimate the association between a country's real per capita growth (realgthpc) and exported-weighted real per capita growth of its trading partners (tpg_aenia for advanced economies, tpg_em for emerging markets, tpg_chn for china). I am using a panel of 26 countries with data at annual frequency. I control for the usual variables that are associated with growth such as inflation, physical and human capital, global growth etc. Moderation, crisis, recovery dummies capture the periods 2003-07, 2008-09, and 2010-11 respectively.

I first run the regression for the period 2001 to 2018. Guided by the Hausman test, I have used country fixed effects. Also, standard errors are clustered at the country-level. I find that a 1% increase in growth of EM trade partners is associated with a 0.5% increase in the growth of the reporting country.
Code:
xtreg realgthpc l.tpg_aenia l.tpg_em l.tpg_chn realpcgdp_5yago_bn gfcf_nomgdp prim_enrol cpi_ep_inflatn depratio open_gdp globalgthpc oiltrdbal_gdp oiltrdbal_gdp_5y gth_commexp_prind crisis_dummy moderation_dummy recovery_dummy, fe vce(cluster CountryNo)
Code:
Fixed-effects (within) regression               Number of obs     =        343
Group variable: CountryNo                       Number of groups  =         26

R-sq:                                           Obs per group:
     within  = 0.3832                                         min =          4
     between = 0.0080                                         avg =       13.2
     overall = 0.1749                                         max =         17

                                                F(16,25)          =      15.10
corr(u_i, Xb)  = -0.5907                        Prob > F          =     0.0000

                                   (Std. Err. adjusted for 26 clusters in CountryNo)
------------------------------------------------------------------------------------
                   |               Robust
         realgthpc |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------------+----------------------------------------------------------------
         tpg_aenia |
               L1. |  -.0420772   .1956026    -0.22   0.831    -.4449283    .3607739
                   |
            tpg_em |
               L1. |   .5208979   .2481788     2.10   0.046      .009764    1.032032
                   |
           tpg_chn |
               L1. |   .1076752   .5621433     0.19   0.850    -1.050081    1.265431
                   |
realpcgdp_5yago_bn |   .0309591   .0211014     1.47   0.155    -.0125001    .0744183
       gfcf_nomgdp |   .2013728   .0805251     2.50   0.019     .0355283    .3672173
        prim_enrol |   .0969751   .0289507     3.35   0.003     .0373501    .1566001
    cpi_ep_inflatn |  -.1490856   .0699263    -2.13   0.043    -.2931015   -.0050697
          depratio |  -.0002485   .0571743    -0.00   0.997    -.1180011    .1175041
          open_gdp |   .0272978    .023562     1.16   0.258    -.0212292    .0758247
       globalgthpc |   .7846087   .2894573     2.71   0.012     .1884603    1.380757
     oiltrdbal_gdp |    .061986    .079659     0.78   0.444    -.1020748    .2260467
  oiltrdbal_gdp_5y |   .0130573   .1709793     0.08   0.940     -.339081    .3651957
 gth_commexp_prind |   .0252099   .0140975     1.79   0.086    -.0038245    .0542443
      crisis_dummy |    .134008   .9356604     0.14   0.887    -1.793021    2.061037
  moderation_dummy |   .8694931   .6094907     1.43   0.166    -.3857765    2.124763
    recovery_dummy |   .5936562   .6663803     0.89   0.381    -.7787797    1.966092
             _cons |  -14.92877   6.315646    -2.36   0.026    -27.93609   -1.921454
-------------------+----------------------------------------------------------------
           sigma_u |  2.7801935
           sigma_e |  2.6945358
               rho |  .51564218   (fraction of variance due to u_i)
------------------------------------------------------------------------------------

rho value in heckman model

$
0
0
Hello dear proffessor;
could you help me please in one small issue; i have panel data with n=7 t=8 ,, I use bootstrap methode with Heckman selection model but i find some diffecult to interpret the results , especialy the validation of rho value as it aqual to 1,more detail is in attachement
i appreciate any help from you
Attached Files

Looping in Stata to extract values from one file to another

$
0
0
Hi all!
So I am a bit stuck on something I have to do.

1. I have a dataset which is multi level, and includes several individual observations for different countries (total 40), for different years/waves. (So for each year, there are 40 countries each having several individual observations of its own). So this is an individual level file.
2. In another dataset, I have the country level variables for all these countries and many more, which has variables like gdp of the country in that particular year
3. I have created an id variable - such that (country-wave) which is the same in both the files.
SO if the code is 47, it represents for country 4 in wave 7.

I want to import the gdp values for each country-wave variable from dataset in 2. such that it gets inputed into all the individual level observations corresponding to that particular (country-wave) variable.

All i need is a loop code such that it would take the gdp value corresponding to the country-wave number (e.g. 47) and put it into the individual file for observations that also correspond to the same country-wave number.

These are two different stata files.

Please help if you can! Will be very well appreciated.

One-sided test of coefficients obtained by mixed

$
0
0
Dear all,
I ran mixed 'outcome' 'treatment' 'binary_covariates' 'metric_covaraites' [fweight=w] || block: . The coefficient for treatment is non-significant, but I would like to be more certain it is not negative. Thus I would like to perform a one-sided test to find out. How can I best do that?



output

Array
The treatment variable is called SRI. All variables except area_aux_rice are binary. The sample contains cross-sectional data of farming households that were matched into groups using Mahalinobis matching.

regards,
Sarah

No observations r(2000) with Regress and SEM

$
0
0
Hello all. I am working with a dataset that contains many categorical variables with values that are still in written word format, which I am trying to convert into numbers. Initially when I typed "summarize" no observations would register for any of the variables, even though I could see the values when I manually scrolled through the dataset. When I tried to run PCA and Regression on some of the variables, these commands would obviously not work because the data were still in string format and needed to be converted to numbers. I fixed that issue by using: generate oldvar=real(oldvar) for all of the variables I was planning on including in my analyses. After running the real() function I was able to obtain summary statistics and observations for all of the variables i needed for my regression. So I thought my problem of the "no observations" error would be fixed when I ran a regression using the new numerical variables. This was not the case, however. I am able to run PCA on several of the variables successfully (Vo1-Vo10), but the regression model I ran still returned the "no observations" error again when I included the now numerical "Race, Age, Education, Ethnicity, and Income" variables. The same error arises when I try to run a SEM with some of the variables. Has anyone found a fix to this "no observations" error arising even after string variables have been converted to numeric? I'll copy and paste my code below:

*Create race dummy variable with 1 as white, 0 as non white
gen race=""
replace race=Q101
replace race="1" if Q101=="White"
replace race="0" if Q101=="Black or African American"
replace race="0" if Q101=="American Indian or Alaska Native"
replace race="0" if Q101=="Asian"
replace race="0" if Q101=="Native Hawaiian or Pacific Islander"
replace race="0" if Q101=="Other"

*Create ethnicity categorical variable
gen ethnicity="."
replace ethnicity=Q102
replace ethnicity="1" if Q102=="Yes"
replace ethnicity="0" if Q102=="No"

*create income categorical variable
gen income="."
replace income=Q100
replace income="1" if Q100=="Less than $19,999"
replace income="2" if Q100=="$20,000 - $39,999"
replace income="3" if Q100=="$40,000 - $59,999"
replace income="4" if Q100=="$60,000 - $79,999"
replace income="5" if Q100=="$80,000 - $99,999"
replace income="6" if Q100=="$100,000 - $149,999"
replace income="7" if Q100=="More than $150,000"

*Create education categorical variable
gen education="."
replace education=Q99
replace education="1" if Q99=="Less than high school"
replace education="2" if Q99=="High school graduate"
replace education="3" if Q99=="Some college"
replace education="4" if Q99=="2 year degree"
replace education="5" if Q99=="4 year degree"
replace education="6" if Q99=="Professional degree"
replace education="7" if Q99=="Doctorate"

*Create age categorical variable
gen age="."
replace age=Q98
replace age="1" if Q98=="16 - 24"
replace age="2" if Q98=="25 - 34"
replace age="3" if Q98=="35 - 44"
replace age="4" if Q98=="45 - 54"
replace age="5" if Q98=="55 - 64"
replace age="6" if Q98=="65 - or older"

*Code value oriententation questions to prep for PCA
gen vo1="."
replace vo1=DT
replace vo1="1" if DT=="Strongly disagree"
replace vo1="2" if DT=="Somewhat disagree"
replace vo1="3" if DT=="Neither agree nor disagree"
replace vo1="4" if DT=="Somewhat agree"
replace vo1="5" if DT=="Strongly agree"

gen vo2="."
replace vo2=DU
replace vo2="1" if DU=="Strongly disagree"
replace vo2="2" if DU=="Somewhat disagree"
replace vo2="3" if DU=="Neither agree nor disagree"
replace vo2="4" if DU=="Somewhat agree"
replace vo2="5" if DU=="Strongly agree"

gen vo3="."
replace vo3=DV
replace vo3="1" if DV=="Strongly disagree"
replace vo3="2" if DV=="Somewhat disagree"
replace vo3="3" if DV=="Neither agree nor disagree"
replace vo3="4" if DV=="Somewhat agree"
replace vo3="5" if DV=="Strongly agree"

gen vo4="."
replace vo4=DW
replace vo4="1" if DW=="Strongly disagree"
replace vo4="2" if DW=="Somewhat disagree"
replace vo4="3" if DW=="Neither agree nor disagree"
replace vo4="4" if DW=="Somewhat agree"
replace vo4="5" if DW=="Strongly agree"

gen vo5="."
replace vo5=DX
replace vo5="1" if DX=="Strongly disagree"
replace vo5="2" if DX=="Somewhat disagree"
replace vo5="3" if DX=="Neither agree nor disagree"
replace vo5="4" if DX=="Somewhat agree"
replace vo5="5" if DX=="Strongly agree"

gen vo6="."
replace vo6=DY
replace vo6="1" if DY=="Strongly disagree"
replace vo6="2" if DY=="Somewhat disagree"
replace vo6="3" if DY=="Neither agree nor disagree"
replace vo6="4" if DY=="Somewhat agree"
replace vo6="5" if DY=="Strongly agree"

gen vo7="."
replace vo7=DZ
replace vo7="1" if DZ=="Strongly disagree"
replace vo7="2" if DZ=="Somewhat disagree"
replace vo7="3" if DZ=="Neither agree nor disagree"
replace vo7="4" if DZ=="Somewhat agree"
replace vo7="5" if DZ=="Strongly agree"

gen vo8="."
replace vo8=EA
replace vo8="1" if EA=="Strongly disagree"
replace vo8="2" if EA=="Somewhat disagree"
replace vo8="3" if EA=="Neither agree nor disagree"
replace vo8="4" if EA=="Somewhat agree"
replace vo8="5" if EA=="Strongly agree"

gen vo9="."
replace vo9=EB
replace vo9="1" if EB=="Strongly disagree"
replace vo9="2" if EB=="Somewhat disagree"
replace vo9="3" if EB=="Neither agree nor disagree"
replace vo9="4" if EB=="Somewhat agree"
replace vo9="5" if EB=="Strongly agree"

gen vo10="."
replace vo10=EC
replace vo10="1" if EC=="Strongly disagree"
replace vo10="2" if EC=="Somewhat disagree"
replace vo10="3" if EC=="Neither agree nor disagree"
replace vo10="4" if EC=="Somewhat agree"
replace vo10="5" if EC=="Strongly agree"

*Convert model variables from string to numeric
generate Race=real(race)
generate Age=real(age)
generate Education=real(education)
generate Ethnicity=real(ethnicity)
generate Income=real(income)
generate Vo1=real(vo1)
generate Vo2=real(vo2)
generate Vo3=real(vo3)
generate Vo4=real(vo4)
generate Vo5=real(vo5)
generate Vo6=real(vo6)
generate Vo7=real(vo7)
generate Vo8=real(vo8)
generate Vo9=real(vo9)
generate Vo10=real(vo10)

Creating first-order difference variables in repeated cross-sectional (i.e. pseudo panel) data

$
0
0
Greetings,

I'm running Stata 15.1 on OSX. I've created a repeated cross-sectional dataset to assess variations in attitudes towards crime (the dependent variable). My time variable essentially stores the month and year in which each survey (31 in total) was conducted. For my independent variable, I created and merged (using the time variable) a newspaper issue-salience index that stores the percent of monthly New York Times articles that refer to crime-related issues. My expectation is that in months in which crime is salient in the media, we will see an increase in the percent of respondents saying crime 'is a serious issue'. To prepare the dataset for analysis, I created (using 'collapse') a variable that stores the mean percent of respondents that gave the 'serious issue' response in each survey (i.e. by year/month). I did the same with the salience index variable (separate dataset) and merged it into the collapsed survey dataset. I ran a simple Pearson correlation between the index and the survey response variable and uncovered a strong relationship (r=0.87). However, a colleague of mine who saw the resulting graph warned me that I 'shouldn't correlate time series with strong autocorrelation' and that, instead, I should 'create first-order difference sequences and correlate those'. I'm not quite sure how to go about doing this. The dataset has no panel ID, so I tried creating one:

Code:
gen id=_n
(note that the id is then simply a number assigned to each survey--31 in total)

I then entered the following:

Code:
xtset id year
To create the 'first difference' variable I tried the following:

Code:
gen indexdiff=D.index
However, Stata subsequently gave me the '31 missing values generation' message.

What am I doing wrong here and how do I get it right? Thanks for your time!

Sample data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(index crime_serious yearmonth year id)
1.0898919 37.634632 441 1996  1
 1.141105  41.15658 449 1997  2
 .9819449 31.580814 453 1997  3
1.1344688  35.43958 475 1999  4
1.2987403   39.7779 487 2000  5
1.1022217  39.37875 488 2000  6
 1.045117 32.872364 521 2003  7
 .7872596 35.538055 522 2003  8
 .8885489  38.24273 523 2003  9
 .9927688  35.79262 524 2003 10
 .7067459  39.30157 539 2004 11
1.0929303 36.767914 548 2005 12
1.0707874  25.04893 572 2007 13
1.0773966  34.76981 573 2007 14
1.0685753  29.70381 576 2008 15
 1.118886   27.0324 580 2008 16
 .9239349  31.63132 584 2008 17
 .7300239 23.623867 597 2009 18
 .7975035  28.98842 598 2009 19
1.1477937 34.304623 613 2011 20
1.0149189  38.20615 614 2011 21
1.1804827   34.5046 624 2012 22
1.3056893  39.55238 648 2014 23
1.2751036  41.03848 649 2014 24
 1.369863  42.47158 650 2014 25
1.8246716  52.22675 662 2015 26
 2.096708  48.12559 667 2015 27
1.6774454  47.23487 668 2015 28
1.5856438  42.08379 669 2015 29
 2.575059  57.32762 686 2017 30
2.7088645   64.2695 689 2017 31
end
format %tm yearmonth

Quick questions about the interaction methods

$
0
0
Dear Researchers,
Greetings,

I have quick questions about interaction variables, please.

At first, I am going to examine the effect of specific standards on the financial reporting quality in the same country for industrial firms for the period 2006-2018. The standards issued let’s say in 2006 and firms started adopting the standards voluntarily. In other words, firms that did not adopt in 2006, they adopt in 2007, and those that did not adopt in 2007 adopted in 2008 and so on. I’ve read a lot about the Difference in Differences method (DID) but it seems that this method will not work in my case as the DID approach require control sample (non-adopters), and in my case, all non-adopters become adopters during the period. Now I am confused about which methods I can use.
To illustrate:
Let us assume the following model:
This is the basic model before studying the effect of the standards.
  1. Financial Reporting quality = α0+ β1 size + β2 Audit + β3 Growth + €.
Where:
Financial Reporting quality, size, and growth are scales (ratio) variables while Audit is a binary variable.
Now, I want to examine the effect of the standards on the financial reporting quality as below:
Financial Reporting quality = α0+ β1size + β2 Audit + β3 Growth + β4 GG + β5GG*size + β6GG*Audit+ βGG*Growth+ €.
Where:
GG = are the standards adopted
Q (1) Can I code GG (1) for a firm (X) for the observations under the adoption period and (0) for the same firm but for observation under the old standard period.
Q(2) can I consider those observations that coded (0) under the old standards as a control?
Q(3) Do the following are correct:
β4 capture the effect of the standards on the financial reporting quality and if it is positive means that the average values of financial reporting quality are higher under the new standards than the old standards keeping other factors constant.
β1 Capture the effect of size before the adoption of the new standards
β5 Capture the effect of size after the adoption of the new standards
β1+ β5 Capture the overall effect (before and after).

Thank you very much in advance for your cooperation.


















Taking Results from Tab2 and Using them to Generate/Recode a new variable

$
0
0
I have a big dataset (1.7million obs) and I need to create contour plots by a member_id within the dataset.

I have the member_id, and each member has about 45,000 obs. After filtering and looking at a subset, I end up with about 35,000 obs for each member.

I tried to use histogram/contour plot to create a contour plot/heatmap and with all of the data it took a really long time to render.

To increase the processing speed and distill the data I did the following....

For the 35,000 obs, I have two continuous variables that are the X and Y variable... and I want their incidence/intensity displayed in a contourplot or a heat map.

I created two categorical variables, a 15-category variable and an 11-category variable that were created by substantive concerns for 1 (known categories with substantive import) and distributional properties for the other (created reasonably sized groups in each interval.

I cross-tabbed the two categorical variables and then created a counter/incidentce variable using the crosstab results....

I did it using brute force...

generate counter=0

recode counter 0=(number in crosstab) if v1==1 and V2==1

recode counter 0=(number in crosstab) if v1==1 and v2==2

I did this for all of the cells in an 11x15 crosstab....

I then created a contour plot with the x variable, the y variable, and used the 'counter' as the z-variable.

The plots work and, with some options, convey the appropriate information.

BUT, this is hugely clumsy and labor intensive when I have 40 'members' and need to do this for 3-4 files per week.

What I would like to do is run the crosstab -

tab v1 v2 - generate the results, and use a mat command to automate the recode of the 'counter_group1' and place each of the cell values in the code to create my counter.

I hope this is clear and I have data to use for an example...

I have set up matrices and run tabs and then used the mat commands to export data into tables, I assume I can do the same and use the mat command to place 'results' into a recode statement that prevents me from manually taking crosstab results and typing them into recode statements.

Any thoughts?

Linear interpolation

$
0
0
Hi!

I have a variable called year in my dataset but this contains just the year 2006, 2009, 2011, 2013, 2015 and 2017. I want to aggregate intermediate years but i do not know how, the other variables have to have an average in those years.

Example: I have 2006 and 2009 in years and i have population to theese years. So, i want to aggregate the intermediate years and make an average from this population in the intermediate years.

I would be grateful if you can help me.
Thanks!

event-study (event-study2)

$
0
0
Hi all,

I am using Stata 16.

My study: I have two periods that I will evaluate; 2008 - 2013 and then 2014 - 2018. I have a total of 63 baseline events - 23 in the 2008 - 2013 period and 40 in the 2014 - 2018 period - and I am using open/close data. Due to data access, I was unable to obtain intraday data (for less than £1500) but I feel using the open/close data will enable me to provide a broad view and still comment on any pre-announcement drift and lasting effects of FOMC news (thus commenting on efficient market theory). To that end, I would like to evaluate the way in which the Dow anticipates FOMC news 3 days prior to the announcement and the way in which news is incorporated, 3 days after the event.

The majority of event studies I have seen appear to evaluate a stock against an index (eg. apple against the S&P 500 is very common) to thus estimate normal performance, abnormal and cumulative abnormal returns, as well as being able to test for significance. Is it possible to conduct an event study with just the Dow Jones?

I am unsure whether anyone has any direction regarding the use of eventstudy2 but I also had the idea to evaluate the effects of unscheduled meetings - so effectively, another set of events. I considered using dummies/ changing (d.var d2.var etc) for x days – leading and lagging (1, 2,3, 4 ) to see if there is any reaction and whether it is more dramatic or not of the scheduled meetings. I suppose they would be in reaction to shocks and a such not working in the same way as the schedule ones. I have done something similar on a project that was not finance related so excuse the novice approach to the event study application.

I have read the 'help eventstudy2' and also used the Princeton , event Studies with Stata guide. However, I I am generating missing values when setting-up my data and I cannot figure what is up with the way I have prepared my data in Excel.

Attached in a copy of my data prepared in excel. I have manually calculated cumulative returns for the whole index, for both periods and I have further calculated cumulative returns for the index over the whole period and removed the event days - this will allow me to compare event-days versus all other trading days. Any direction at this stage would be much appreciated.

Thanks in advance.
Viewing all 65116 articles
Browse latest View live


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