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

How to capture some of the inequality indices provided by "inequal" command

$
0
0
I am using the following command to generate inequality indices for the variable "rendomdefpc" for each combination of 27 states (uf) and 5 years (ano):

levelsof uf, local(ufs)

foreach c of local ufs {
levelsof ano if uf == `c', local(anos)
foreach y of local anos {
display `"uf == `c', ano == `y'"'
inequal rendomdefpc [fw=pesopes] if uf == `c' & ano == `y'
}

}

Among the indices that the results of the command "inequal" provide I'm only interested in the Gini coefficient, in the Theil mean log deviation measures and in the Theil entropy measure, and tried to use the following syntax to capture them:

capture postutil clear
postfile handle ufs ano gini theil_t theil_l using desiguald, replace

levelsof uf, local(ufs)

foreach c of local ufs {
levelsof ano if uf == `c', local(anos)

foreach y of local anos {
display `"uf == `c', ano == `y'"'
inequal rendomdefpc [fw=pesopes] if uf == `c' & ano == `y'
post handle (`c') (`y') (`r(gini)') (`r(theil_t)') (`r(theil_l)')
}
}

postclose handle
The syntax did not work and Stata generated the following error message:

invalid syntax
post: above message Corresponds to 3 expression, variable gini
I would once again be able to count on your help and solve this problem more.

Thanks in advance

Girlan

how to do calculations with the coefficients that i obtained

$
0
0
after running OLS regression,

I want to automatically do calculations with the coefficients I obtained.

if for example I want to get a number by doing

value = (b1 + b2)/1 - (a1 +a2)

how can I code this?

Thanks

Difference between regressions coefficients

$
0
0
Hello
I am trying to test the difference between my regression coefficients to see whether the difference is significant. The regression is in the following form
Yij01(2005ij∗WINij)−β2(2003ij∗WINij)+β32005ij42003ij5WINijij

I am trying to figure out how to get the difference between beta 1 and beta 2 in STATA to test whether this difference is significant.


Panel cointegration, Westerlund

$
0
0
Hi all,
I am testing for cointegration in panel, all my variables are I(1). Now, I want to use Westerlund xtwest, do I need to run the test in first difference? And do you know what is the difference if I include deterministic components or not?

Thank you in advance.

BLP Demand Model

$
0
0
Am estimating a random coefficient discrete choice demand model using the blp command in Stata 14 . Does anybody know how to get the Hansen statistic of the underlying GMM procedure of this estimator?
I.e. I wanna figure out if the instruments that I used for the endogeneous price variable are correctly specified.
Thanks

Counting Observation across different variables

$
0
0
Hi All,

In the example below is there any way to calculate the number of observations for each country and every year with "Goods Exports > 100" by STATA. Looks like constructing 2 countries * 3 years matrix.

Thanks in advance for your help
Country Year Goods Exports
Coun_1 2000 200
Coun_1 2000 150
Coun_1 2000 75
Coun_1 2000 50
Coun_1 2000 120
Coun_1 2001 70
Coun_1 2001 140
Coun_1 2001 25
Coun_1 2001 225
Coun_1 2001 150
Coun_1 2002 275
Coun_1 2002 120
Coun_1 2002 60
Coun_1 2002 85
Coun_1 2002 210
Coun_2 2000 155
Coun_2 2000 90
Coun_1 2000 30
Coun_2 2000 140
Coun_2 2000 200
Coun_2 2001 65
Coun_2 2001 145
Coun_2 2001 175
Coun_2 2001 85
Coun_2 2001 220
Coun_2 2002 95
Coun_2 2002 135
Coun_2 2002 90
Coun_2 2002 45
Coun_2 2002 210

poi2hdfe error: unrecognized command: *hdfe

$
0
0
Hello Statalist,

I am having a strange problem with poi2hdfe. When i execute a command such as below, i get an error that hdfe is not recognized command.

Code:
 poi2hdfe v lngdp_i lngdp_j, id1(it) id2(jt) cluster(ij)

Total Number of observations used in the regression -> 98058

Starting Estimation of coefficients

unrecognized command:  hdfe
r(199); t=0.80 22:51:06

As you see, hdfe is not a separate command. I have uninstalled and reinstalled poi2hdfe, and reghdfe several times, but still having the problem. Does anyone know hoe to fix this?

Im using Stata 13 MP, with Windows 10.

Regards,
Dias

lclogit error - weights must be the same for all observations in a group r(407)

$
0
0
Dear Statalist -

I am using -lclogit- to analyze data from a choice experiment using the following model:

Code:
lclogit choice attribute_1 attribute_2 attribute_3 .... attribute_n, id(choice_maker_id) group(choice_experiment_question_id) nclasses(3)
I get the following error when I run this model:

Code:
Iteration 0:  log likelihood = -25298.937
weights must be the same for all observations in a group
r(407);
I suspect the error is caused by the way I have numbered the variable "choice experiment question" as 1-8 for all choice makers, since each person had to respond to 8 choice sets. Does anyone know if the choice experiment identifiers must be unique across all choice makers? Instead of 1-8 they must be 1-8 for choice maker 1, 9-17 for choice maker 2, and so forth?

Thanks for your help!


Correlation - Stock Returns

$
0
0
Dear Stata Users,

I'm trying to compute the yearly correlation between two stocks in Stata. I have monthly Returns (so I have for example Jan94 as a variable and the corresponding January 1994 Returns for different stocks).
Any help?

Thank you very much!
Quentin

Finding a matching observation in another variable

$
0
0
Dear Statalist users,

There is a table that looks like this:
person_id mother_id educ mother_educ
1 5 10 ?
2 6 5 ?
3 10 15 ?
4 12 3 ?
5 15 8 ?
6 20 13 ?
So I have a person id, the id of his/her mother and the education of the person in one line. What I need to find is the education of the mother. So for example in this table the mother of the person #1 is the person #5. We know that the education of the person #5 is equal to 8, so this is basically mother's education that I need to save as a variable "mother educ".

The question is how can I match the observations from the column 'mother id' with the observations from 'person id' to save the corresponding 'educ' values? I hope you understand what I mean

Thanks a lot in advance, any advice would be very helpful.

Interpreting margins after ivprobit

$
0
0
Dear all,
I've estimated an ivprobit model with my Stata 14.0, and subsequently estimated the marginal effects as follows:
Code:
 ivprobit inaba d_cocus d_cocom d_cocon d_cores d_cocross turnmar  ln_rrdinx i.emp12 (sumcoupled = anyfund obsprs obsfin obsamk i.ho i.div) [pweight = weight], first vce(robust) noci nolog
margins, dydx(*) atmeans
inaba d_cocus d_cocom d_cocon d_cores d_cocrossanyfund being binary variables, i.emp12 i.ho i.div catgorical variables, sumcoupled obsprs obsfin obsamk ordinal variables and turnmar ln_rrdinx continuous variables. Sumcoupled is the suspected endogenous variable.

I have two questions about the following results:
1. Margins and coefficients are identical, am I using the wrong margin command?
2. Am I correct in interpreting that a marginal coefficient of, for example, 3.89, means that if d_cocus=1 there is a 389% larger probability that inaba =1, than when d_cocus=0?

Thank you very much,
Marco

The result is the following:

Code:
Probit model with endogenous regressors         Number of obs        =        2,244
Wald chi2(10)        =        440.27
Log pseudolikelihood = -28946.945               Prob > chi2        =        0.0000


Robust
Coef.   Std. Err.      z    P>z

inaba        
sumcoupled   -2.395854   .2209334   -10.84   0.000
d_cocus    3.896818    .530055     7.35   0.000
d_cocom    3.559508   .4654797     7.65   0.000
d_cocon    3.072191   .5139967     5.98   0.000
d_cores    2.666163   .5053396     5.28   0.000
d_cocross    5.140044   .6715067     7.65   0.000
turnmar      .45121   .3776967     1.19   0.232
ln_rrdinx   -1.130753   1.542433    -0.73   0.463
            
emp12
50     .0184049   .0706193     0.26   0.794
250     .5754919   .2191246     2.63   0.009
            
_cons   -.2210119   .2383996    -0.93   0.354

sumcoupled  
d_cocus    1.638257   .2045396     8.01   0.000
d_cocom    1.482706   .2343135     6.33   0.000
d_cocon    1.283468    .197789     6.49   0.000
d_cores    1.113973     .18105     6.15   0.000
d_cocross     2.12796   .2687844     7.92   0.000
turnmar     .162242   .1537142     1.06   0.291
ln_rrdinx   -.4632076   .7066246    -0.66   0.512
            
emp12
50    -.0063611   .0327474    -0.19   0.846
250     .2017088   .0967137     2.09   0.037
            
anyfund   -.0000792   .0071347    -0.01   0.991
obsprs    .0008944   .0048381     0.18   0.853
obsfin   -.0034943   .0062173    -0.56   0.574
obsamk   -.0070164   .0100014    -0.70   0.483
            
ho
1     .0120017   .0159715     0.75   0.452
2    -.0173811   .0330005    -0.53   0.598
3     .0055064   .0158216     0.35   0.728
            
div
11     .0118006    .026879     0.44   0.661
13    -.0243965   .0436818    -0.56   0.576
14    -.0399069   .0573808    -0.70   0.487
15    -.0068647   .0271339    -0.25   0.800
16    -.0044471    .018258    -0.24   0.808
17     .0394411   .0600418     0.66   0.511
18     .0012958    .021753     0.06   0.952
19      .024285   .0300959     0.81   0.420
20     .0003367   .0246237     0.01   0.989
21     .0011733   .0182773     0.06   0.949
22     -.026578   .0379156    -0.70   0.483
23     .0012635   .0170697     0.07   0.941
24    -.0104179   .0312036    -0.33   0.738
25    -.0012584   .0153595    -0.08   0.935
26    -.0192463   .0287365    -0.67   0.503
27    -.0171457   .0305138    -0.56   0.574
28    -.0112913   .0211876    -0.53   0.594
29     .0086696    .022577     0.38   0.701
30     .0114836   .0350493     0.33   0.743
31    -.0058103   .0190109    -0.31   0.760
32       .02945   .0395921     0.74   0.457
33    -.0213457   .0410644    -0.52   0.603
            
_cons    -.004602   .0236016    -0.19   0.845

/athrho    2.711991   1.360701     1.99   0.046
/lnsigma   -.8796441   .0810799   -10.85   0.000

rho    .9912196     .02379
sigma    .4149306   .0336425

Instrumented:  sumcoupled
Instruments:   d_cocus d_cocom d_cocon d_cores
d_cocross turnmar ln_rrdinx 50.emp12
250.emp12 anyfund obsprs obsfin
obsamk 1.ho 2.ho 3.ho 11.div 13.div
14.div 15.div 16.div 17.div 18.div
19.div 20.div 21.div 22.div 23.div
24.div 25.div 26.div 27.div 28.div
29.div 30.div 31.div 32.div 33.div

Wald test of exogeneity (/athrho = 0): chi2(1) =     3.97 Prob    >    chi2    =    0.0463

note: 6 failures and 0 successes completely determined.

Code:
   
Delta-method
dy/dx Std. Err. z P>z [95% Conf. Interval]
sumcoupled -2.395854 .2209334 -10.84 0.000 -2.828875 -1.962832
d_cocus 3.896818 .530055 7.35 0.000 2.85793 4.935707
d_cocom 3.559508 .4654797 7.65 0.000 2.647185 4.471832
d_cocon 3.072191 .5139967 5.98 0.000 2.064776 4.079606
d_cores 2.666163 .5053396 5.28 0.000 1.675715 3.65661
d_cocross 5.140044 .6715067 7.65 0.000 3.823915 6.456173
turnmar .45121 .3776967 1.19 0.232 -.2890619 1.191482
ln_rrdinx -1.130753 1.542433 -0.73 0.463 -4.153865 1.89236
emp12
50 .0184049 .0706193 0.26 0.794 -.1200064 .1568163
250 .5754919 .2191246 2.63 0.009 .1460157 1.004968
anyfund 0 (omitted)
obsprs 0 (omitted)
obsfin 0 (omitted)
obsamk 0 (omitted)
ho
1 0 (omitted)
2 0 (omitted)
3 0 (omitted)
div
11 0 (omitted)
13 0 (omitted)
14 0 (omitted)
15 0 (omitted)
16 0 (omitted)
17 0 (omitted)
18 0 (omitted)
19 0 (omitted)
20 0 (omitted)
21 0 (omitted)
22 0 (omitted)
23 0 (omitted)
24 0 (omitted)
25 0 (omitted)
26 0 (omitted)
27 0 (omitted)
28 0 (omitted)
29 0 (omitted)
30 0 (omitted)
31 0 (omitted)
32 0 (omitted)
33 0 (omitted)
Note: dy/dx for factor levels is the discrete change from the base level.

The validity of oral glucose tolerance test (OGTT) using Stata!!!

$
0
0
Reproducibility of OGTT (Oral glucose tolerance test).
Glucose levels were measured for the same people, but taken at different times one after another, 2 weeks time interval.
I want to know if the mean difference is low or high to say that the test is valid or not valid.

1. How can I interpret the paired ttest?
2. How can I interpret the batplot?
3. How can I construct and interpret the continous ROC curves?

Any other Stata test I can use to prove the validity of my OGTT?


Thanks.

Specify Coefficients for Cross Validation

$
0
0
Hi,

I have created beta coefficients by merging coefficients from a GLMM with those from a meta analysis. I would like to cross validate these merged beta coefficients on a new data set by running a GLMM. However, the cross validation options do not seem to let me write in or fix my own beta coefficients to use in a cross validation scoring analysis. It seems that you can run a GLMM and then use the calculated/saved coefficients to be scored, but I would like to set my own coefficients that I have come up with by merging the original GLMM with my meta analysis, not the ones that were calculated directly from the original GLMM. Is there a way for me to manually specify or fix beta coefficients and then feed these into a run of a GLMM on the new data to be scored?

Thanks!

Ryan

0/1 variable not reading as 0/1 with lclogitml

$
0
0
My second and last post to Statalist today:

I am using lclogitml to generate standard errors for coefficients from a latent class model using clogit.

For some reasons I get the following error each time I use lclogitml:

Code:
choice is not a 0/1 variable which equals 1 for the chosen alternative.
r(450);
I have checked a few previous Statalist posts about this issue and there was not resolution to those posters same issue.

I have checked my outcome variable y (called choice) many times to ensure that the only values it takes on are 0/1. I used recast to change the storage type of the variable and this did not resolve the issue.

I used example data from this presentation to see if I could recreate the error with this other data and lclogitml worked just fine.

What are the possible reasons why Stata is not reading this variable as 0/1 even though I see it as such? Perhaps this error is being generated for another reason that is not related to the 0/1 nature of my outcome variable?

Thank you for your help!


Area under ROC curve

$
0
0
Hello,

Does anyone here know how to get the ROC curve after using -melogit- command? I know that -lroc- gives you the area under ROC but it doesn't work with the melogit command. I appreciate your replies.

Thanks

dealing with sample sizes in logistic regression analysis

$
0
0

I did a matched case control study in Uganda looking at Determinants of Severe malaria in Children (325 age-matched pairs; severe malaria cases vs. uncomplicated malaria controls). I am doing a sub-group analysis of risk factors by type of severe malaria syndrome; cerebral malaria (59 age-matched pairs) and severe malaria anemia (141 age-matched pairs).

Using the clogit command I run a regression model for the cerebral malaria sub-group which resulted in some explanatory variables (EV) having OR with extremely wide CI. Based on the VIF scores, and the Conditional Index mullticollineraity doesn't seem to be a problem in the model. I therefore think the wide CI’s are attributable to small sample size numbers within the groups
I've used to approaches to try and over overcome this challenge:

1. Drop the EV; an undesired option for I lose the influence of the variable in the model.

2. firthlogit command; and the problem appears to be addressed

However, I am not sure if the firthlogit commands is applicable to matched data, and if not what are my options ?

Thanks

Arthur Mpimbaza
Email: arthurwakg@yahoo.com

Interaction Variable or Subgroup Comparison

$
0
0
Good afternoon,

I am working on a project that investigates the effect of media consumption on perception of corruption, and I would like to also examine the prevalence of such causal relationships among different gender and race group. My analytic approach is to first compare the effects on men and women, and then women by race and men by race. I used two ways to do the gender comparison, the interaction and the "suest". Here are the example commands (I took out all the control variables to make it look cleaner):

Code:
xi: regress perception black asian latino i.male*local_print_newspaper
Code:
reg perception black asian latino local_print_newspaper if male==1
est store male
reg perception black asian latino local_print_newspaper if male==0
est store female
suest male female
test [male_mean]local_print_newspaper=[female_mean]local_print_newspaper
Unfortunately, I noticed that the results of each model look drastically different. The interaction variable is significant, while the "suest" test shows that the difference between male and female is not significant. I suppose it's because of my small sample size (1,000 men and 1,000 women), and when using suest I lost statistical power since it separates men and women into two regression models. So here are my questions: first, does my assumption make sense, that the interaction variable is perhaps a better way to analyze the subgroup differences? Second, if indeed, by separating men and women I lose statistical power, what would be a better way to do the comparison of men by race and women by race?

I'll put my commands of men by race here too. I separate men and women into two datasets because I can't really think of another way to do the men by race and women by race analysis.
Code:
forval i=0/1 {
preserve
keep if male==1
save male, replace
restore
}
clear
use "C:\Users\male.dta"
Code:
by race: reg perception local_print_newspaper
And to test if the coefficients are significantly different from one race to the other:
Code:
xi: regress perception black asian latino local_print_newspaper i.black*local_print_newspaper
xi: regress perception black asian latino local_print_newspaper i.asian*local_print_newspaper
xi: regress perception black asian latino local_print_newspaper i.latino*local_print_newspaper
xi: regress perception white asian latino local_print_newspaper i.asian*local_print_newspaper
xi: regress perception white asian latino local_print_newspaper i.latino*local_print_newspaper
xi: regress perception white black latino local_print_newspaper i.latino*local_print_newspaper
Please let me know. I'm really concerned if I'm actually doing the right thing.
Any advice is hugely appreciated.

Best,
Kevin

Why do svy:total and total give different standard errors when pweight is used?

$
0
0
Hello eveyone,

I found that svy:total and total give different standard errors when pweight is used. This difference dose not occur for svy:mean & mean, and svy:prop & prop.

Frankly, I did not expect that difference, and obviously I misunderstood something. Could anyone tell me why svy:total and total give different standard errors? Thank you very much.


Code:
clear all
set obs 10
gen y=cond(_n<=2, 1, 0  )
gen w=cond(_n<=2, 3, 0.5)



total y [pw=w]
Total estimation                  Number of obs   =         10
--------------------------------------------------------------
             |      Total   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
           y |          6          2      1.475686    10.52431
--------------------------------------------------------------

svyset [pw=w]
svy: total y
Survey: Total estimation
Number of strata =       1        Number of obs   =         10
Number of PSUs   =      10        Population size =         10
                                  Design df       =          9
--------------------------------------------------------------
             |             Linearized
             |      Total   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
           y |          6          4     -3.048629    15.04863
--------------------------------------------------------------



mean  y [pw=w]
Mean estimation                   Number of obs   =         10
--------------------------------------------------------------
             |       Mean   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
           y |         .6         .2      .1475686    1.052431
--------------------------------------------------------------

svyset [pw=w]
svy:mean  y
Survey: Mean estimation
Number of strata =       1        Number of obs   =         10
Number of PSUs   =      10        Population size =         10
                                  Design df       =          9
--------------------------------------------------------------
             |             Linearized
             |       Mean   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
           y |         .6         .2      .1475686    1.052431
--------------------------------------------------------------



prop  y [pw=w]
Proportion estimation             Number of obs   =         10
--------------------------------------------------------------
             | Proportion   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
y            |
           0 |         .4         .2      .0919048    .8145221
           1 |         .6         .2      .1854779    .9080952
--------------------------------------------------------------

svyset [pw=w]
svy:prop  y
Survey: Proportion estimation
Number of strata =       1        Number of obs   =         10
Number of PSUs   =      10        Population size =         10
                                  Design df       =          9
--------------------------------------------------------------
             |             Linearized
             | Proportion   Std. Err.     [95% Conf. Interval]
-------------+------------------------------------------------
y            |
           0 |         .4         .2      .0919048    .8145221
           1 |         .6         .2      .1854779    .9080952
--------------------------------------------------------------

Summing Across Coded Variables

$
0
0
Hi,

I am using stata 13.

I have a Var1a which is coded with values from 1 to 5. Var1b is also coded with values from 1 to 5. Each value has a frequency. I am trying to count the total number of observations across Var1a and Var1b to get a total frequency figure for each label.

For example:
Var1a Var1b
1 50 1 20
2 40 2 30
3 20 3 10
4 10 4 25
5 5 5 35

I would like to create a variable Var2 which has the freq values 1:70, 2: 70 etc.

I have been looking at the egen functions but I can't seem to find a command that would do the trick.

Thanks,

Error in exporting data into csv

$
0
0
Dear all,

I tried to export my data into an csv-file. But I always get this output:
Array
Could anyone help me why this error occurs?

Thanks for your help!
Kindly, Kim
Viewing all 73282 articles
Browse latest View live


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