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

Chow test after -xtreg,fe-: Problem with aweight

$
0
0
Hi everyone,

I follow the post of Gould (http://www.stata.com/support/faqs/st...nd-chow-tests/) to do the Chow test, but with -xtreg,fe-

I first replicate his code with a data from Stata, and it works. I have the coefficients in Ouput 3 similar with Ouput 1. (See code below).
However, when I replicate this code with my own data, it still works until the last order.
And I have the error message (for OUTPUT 3):
weight must be constant within id
r(199);
Anyone could give me suggestions about my problem?

Code:
//I try with this data and it works
   
use http://www.stata-press.com/data/r13/nlswork, clear
    
/*Output 1*/
    xtreg ln_w msp age if race==1,fe cluster(id) r
    xtreg ln_w msp age if race==2,fe cluster(id) r
    
    cap drop g2*
    gen g2 = (race==2)
    gen g2msp = g2*msp
    gen g2age = g2*age

​​​​​​​/*Output 2*/    
    xtreg ln_w msp age g2msp g2age,fe cluster(id) r

    cap drop r
    predict r, resid
    sum r if race==1
    cap drop w
    gen w = r(Var)*(r(N)-1)/(r(N)-3) if race==1
    sum r if race==2
    replace w = r(Var)*(r(N)-1)/(r(N)-3) if race==2

​​​​​​​/*Output 3*/
    xtreg ln_w msp age g2msp g2age [aw=1/w],fe cluster(id) r

-mimrgns- and Predicted Probabilities with Multilevel Data

$
0
0
Dear all,

I am trying to estimate marginal effects and predicted probabilities for a multilevel (logistic) analysis, treated with multiple imputation procedures. I have been able to get the linear predictions as outlined in the reference manual. However, after reading several posts on obtaining predicted probabilities, none of the commands appear to work.

I have attempted to use both predict( outcome(#)) and predict(pr) in the command line, however, neither option is allowed. My code is as such:

Code:
mi estimate, dots or: meqrlogit mviolence ib(6).age ib(1).nordic ib(3).incomeq ib(4).famdec cen_gii cen_unempg ib(1).partneremp(cen_sprotect cen_womeduc) || country: 
mimrgns, predict(outcome(1)) at(partneremp=(0 1 2) cen_sprotect=(-544.1996 -272.0998 0 272.0988 544.1996)) cmdmargins
Code:
mi estimate, dots or: meqrlogit mviolence ib(6).age ib(1).nordic ib(3).incomeq ib(4).famdec cen_gii cen_unempg ib(1).partneremp(cen_sprotect cen_womeduc) || country: 
mimrgns, at(partneremp=(0 1 2) cen_sprotect=(-544.1996 -272.0998 0 272.0988 544.1996)) ///
predict(pr) cmdmargins
*N.B. I cite cmdmargins to allow for marginsplot*

Both commands, however, return the r(198) error that such an option is not allowed.

Is there a way to obtain these predicted probabilities? Any suggestions would be much appreciated.

Apologies for any inconvenience.

Kind Regards,

Patrick

Fractional polynomials with clogit

$
0
0
Hi all,

I have matched case-control data (one case and one control per group; 596 subjects in 298 groups) and a number of continuous exposure variables (all positive values). I am trying to fit a conditional logistic regression model with fractional polynomials for the continuous exposure variables (eg subject age) but am getting the following error message:

. fp <age>, replace: clogit event <age>, group(pair) or
redundant or inconsistent constraints
When fitting the null model, fp: ran the command clogit and it produced the above error
message.
r(412);

The 412 error message reads:

. * Return code 412 redundant or inconsistent constraints; For instance, you are estimating
> a constrained model with mlogit. Among the constraints specified is at least one that is redun
> dant or inconsistent. A redundant constraint might constrain a coefficient to be zero that some
> other constraint also constrains to be zero. An inconsistent constraint might constrain a coeff
> icient to be 1 that some other constraint constrains to be zero. List the constraints, find the
> offender, and then reissue the mlogit command omitting it.

But I am unclear how to list the constraints.

If I avoid the fp null model, the specified fractional polynomials are fitted successfully. For example:

fp <age>, fp(-2 2) replace: clogit event <age>, group(pair) or


Fractional polynomial comparisons (including the null model) are completed successfully when I use a dataset used in the Stata Manual when there are multiple positive outcomes within groups (Stata commands below).


But I get the same error message when I try fp with clogit using a dataset used in the Stata Manual also with only one case and one control per pair (Stata commands below). Using those same data, the fractional polynomial comparisons (including the null model) are completed successfully using stcox (Stata commands below).


I am missing some (probably simple) logic here. Is it not possible to run fractional polynomial comparisons that include the null model with clogit with one case and one control per group?

Many thanks for any help.


John


*Try fp when there are multiple positive outcomes within groups:

use http://www.stata-press.com/data/r13/clogitid

fp <x2>, replace: clogit y x1 <x2>, group(id)

Output omitted but fractional polynomial comparisons are completed successfully


*Try fp with clogit using a dataset used in the Stata Manual also with only one case and one control per pair

use http://www.stata-press.com/data/r14/lowbirth2, clear

fp <lwt>, replace: clogit low <lwt>, group(pairid) or

Output omitted but fractional polynomial null model not fitted:

"redundant or inconsistent constraints
When fitting the null model, fp: ran the command clogit and it produced the above error
message.
r(412);"


*Try fp with the equivalent stcox model

use http://www.stata-press.com/data/r14/lowbirth2, clear

gen time=1+(low==0)

stset time, failure(low==1)

fp <lwt>, replace: stcox <lwt> , strata(pairid) hr

Output omitted but fractional polynomial comparisons are completed successfully

Saving results of Looping in Matrix

$
0
0
can someone please guide me through the process of saving the results of a loop in a matrix?
do i need to generate a matrix before the loop and then fill it in?
basically i am doing a power analysis of a statistical test (durbin H ), i need to perform the test 1000 times running the loop from 1 to 1000 and then saving the result (0 or 1) of each test in a column matrix, so that i can later add the elements of the matrix and find the power of the test?

What is the method xtreg, fe uses to predict the fixed effects?

$
0
0
Dear users,

What is the method xtreg, fe uses to predict the fixed effects? Does it run an auxiliary areg regression?

So far I have not found this in Stata documentation (Methods and Formulas, etc), nor in this forum.

I ask this because they always seem to approximate a normal distribution. However, the theory behind the FE estimator (so far as I know), never assumes a formal distribution behind these effects, just some linear correlation with some regressors. If normality is part of the assumptions in their prediction, I would like to try the results under different assumptions.

Thanks!
Alan.

Ordered probit and margins

$
0
0
Hi,

In a project on the determinants of job satisfaction (answers coded 1 to 5), I have some doubts.

Using the ordered probit model and the margins command, how should I code, or execute my analysis, in order to answer the the following questions (extending the analysis beyond average marginal effects).

1. Which are the most important (most probable) job related independent variables in order to lift those answering the lowest job satisfaction level (1) to the second lowest level of job satisfaction (2)?
2. Which are the most important (most probable) job related independent variables in order to lift those answering the second highest level of job satisfaction (4) to the highest level (5)?

Sincerely.

/Daniel Lind



Dynamic Logit Model with Independent Structure by using the Maximum Likelihood estimating method

$
0
0
Hi guys ! I'm Wesley.

I'm doing a thesis that is about Predicting Recurrent Financial Distress. In the thesis, I used models: Dynamic Logit Model with Autocorrelation Structure by using the Generalized Estimating Equations (GEE) method and Dynamic Logit Model with Independent Structure by using the Maximum Likelihood estimating method to predict . But I do not know how to run (panel data) Dynamic Logit Model with Independent Structure by using the Maximum Likelihood estimating method in Stata ? Could you guys please give me some solutions or teach me how to code this model ?
I attached the paper that I cited below

Thank You All !

Suitable Regression Method - Panel structure (3 firms, 5 years): Dependent variable varies only firm-wise not year-wise.

$
0
0
Hi all.

Can you suggest an appropriate method of regression for the data given below?

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(code year y x1 x2 x3)
1 2001 2 12 1 9
1 2002 2 13 1 8
1 2003 2 11 3 8
1 2004 2 14 2 9
1 2005 2 14 1 7
2 2001 1  2 2 6
2 2002 1  2 4 7
2 2003 1  3 5 5
2 2004 1  5 6 4
2 2005 1  6 7 4
3 2001 4 21 8 5
3 2002 4 22 9 6
3 2003 4 22 7 7
3 2004 4 24 6 3
3 2005 4 18 8 2
end


Explanation: The structure is panel, where code represents firms in the data set (3 firms) for 5 years. "y" is the dependent variable while "x1" to "x3" are three independent variables. However, if you notice, the dependent variable behaves such that it remains constant for each firm during all the sample years. That is, it varies only firm-wise not year-wise. On the other hand, all independent variables vary across all firms in all years.

One possible way would be to convert data into cross section by taking mean or median values of each independent variable and then run the OLS regression. However, this would drastically reduce the sample size, leaving only 3 observations.

Is it advisable to run OLS (treating the data as cross section) on this structure as it is? Or is there any superior method which can be used and is supported in STATA?

Please comment. Thanks.




Fixed Effects and Random Effects Insignificant Results

$
0
0
Hello, Im analyzing a set of potential drivers of Income Inequality for Latin American Countries. I started working with the SWIID database using a 5 years average for the estimation. My dependent variable is the Gini Index and Im using the following set of explanatory variables: The lagged value of Gini index, log GDP per capita and its squared, logarithm of population density, gross enrollment ratio (secondary), female mortality rate, age dependency ratio, natural resources rents, gross capital formation, government spending, foreign direct investment, trade openness, personal remittances, political and social globalization democracy, foreign aid and civil war, all of them collected form the literature developed so far. However, with both fixed effect and random effects I have highly insignificant coefficient (I control for time dummies as well).

Given this, I decided to change the measure of the Gini Index, and I use the EHII database as alternative, with exactly the same procedure. However my explanatory variables are still highly insignificant.

Anyone have an idea of what is going on with my estimations? I really appreciate any feedback.

Kind Regards

Panel Data: How to create a flag indicating if a condition is true at time t and all future times?

$
0
0
Hello, all,

I've got some panel data for a randomized trial, and I'm trying to link the data to the diagnoses in Medicare claims files. I have flags for whether a person meets the diagnostic criteria for a number of chronic conditions in the current year. I would like to create a flag indicating that someone has had a disease that turns on when they get the disease in one year, and then stays on, regardless of whether they currently have the disease.

For example, consider dementia, which is often not coded in medical claims. Say I'm willing to assume that once someone has been flagged as having dementia in 2001, they probably still have it even if the 2003 medical claims don't say they do. However, I don't want their line for the year 2000 to say that they do.

I currently have the first 3 columns, and I'm trying to create the 4th.
Name Year Current Dementia Dementia Now or Prior
Mrs Vang 2000 0 0
Mrs Vang 2001 1 1
Mrs Vang 2002 0 1
Mrs Vang 2003 0 1
I believe that this will accomplish my goal, and I'd like to ask if people think this is correct:

tsset ID year
gen dementiaprior = currentdementia
replace dementiaprior = L.dementiaprior if dementiaprior == 0 & L.dementiaprior == 1

This appears to work in the test data I've set up (which is in Stata 11 format), and from the tsset documentation, it appears that the xt suite of commands (e.g. xtgee and xtregress) will work after I've tsset the data. Am I right? If I am, can anyone think of a more parsimonious way to do this?

Thanks for any assistance you can provide.

Special regressors &amp; endogenous discrete variables

$
0
0
Hi everyone,

I have a setting with a discrete endogenous variable that I'm trying to estimate. In theory, estimating this would directly apply Arthur Lewbell's excellent innovations. In practice, I'm running into a problem.

Let's denote Y as the outcome, E as the endogenous discrete 1/0 variable, X as controls, and Z as the instrument(s). Lewbell invented something called "special regressors" via the sspecialreg command.

The notation applied to this problem is:

sspecialreg Y V, trim(2.5) kdens exog(X) endog(E) iv(Z) hetero

where V is the special regressor.

My questions fall into a simple stata issue, and a more technical issue.

The technical problem is that the estimated coefficient is way too large in absolute value to be right, probably because I am not using a valid special regressor. Since I am working with microdata, I used age as a special regressor, but I think it's failing because -- although it's exogenous -- it's not conditionally independent of the error. So, what would be an example of an ideal special regressor?

The small stata issue is that, although I have installed the "kdens" routine, it's telling me that I don't have it. The only way I ran the estimation above to find the implausible coef estimate was through my university server.

Thank you!

tabdisp with weights

$
0
0
Hi all,

I would like to add weights to the below command but weights are not accepted using tabdisp.

Is there a way around writing the below in Stata?
tabdisp x [aw=coeff] if x==123, c(mean mode p80) format(%2.1f)

Thanks.

Transferring t-test and variance test results to excel sheet

$
0
0

Dear Members,

Could you please help me with writing a code. What I am trying to do is to collect data in the following way:

Group | Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]) (p-values for variance test 3 columns) (p-values for t-test equal variance 3 columns) ( p-values for t-test of unequal variance 3 columns)
Something like that. Array


I attached a photo. I have one outcome and 40 variables and I would like to have the results each beneath each other

Amin

How to assign time to variable in panel data

$
0
0
Hi all,
I'm currently using Stata 12 and I'm running into difficulty with the panel data I'm managing. The panel data has only two time periods, so called yr (0: normal year; 1: disaster year) so each observation with identifier hhcode is sampled in both normal year and disaster year. I would like to create a new variable taking the value of 1 if at least one measure applied in disaster year and none in normal year, and 0 otherwise. Which means n6_adapt==1 if yr==1 and n6_adapt==0 if yr==0. Which commands should I use so that Stata will understand that for each observation (each hhcode), the two above conditions for normal year and disaster year have to be satisfied? Thank you so so much in advance for your help! _Kim

Draw xline on top of plot

$
0
0
I would like to draw an vertical that appears on top of a plot from a "graph twoway" command. I have seen solutions on this forum that use the "scatteri" command to manually draw the vertical line.

My problem is that I do not know beforehand what parameters to use for the "scatteri" command. That is, I don't know the rage of y-values to use for the vertical line. After the graph is produced, I can eyeball the graph and plug in numbers, but I would like to automate the process. Is there a way to figure out what y-values to use beforehand?

I figure that if I can run the command once, without "scatteri" and then recover the y-coordinates of the plot region, I may be able to use those in a subsequent command with "scatteri." However, I do not know how to extract the y-range of a previous graph. Is there a way to find out the y-range of a graph in memory?

How to set const

$
0
0
Hello,
New to Mata, and do not seem to find the answer for a simple question.

In Mata, how to declare a const variable (not the kind in regression models) but the one that most modern programming languages use to name a value eg in Pascal
const ExchangeRate = 1.14;
Thanks,

Loop through Strings Containing Spaces in a Variable / Macro

$
0
0
I have two string variables that contain movie names: Name1 and Name2. Some values repeat, both within each one and across the two.

Example:

Names1

Indiana Jones
James Bond

Names2

James Bond
Top Gun

I need to loop through all of the movie names, but only once per name.

The general steps I have in mind:

1. Create a macro that contains a unique list of names from both variables.

2. Loop through the macro and tabulate each movie name with a third variable.


I am having a lot of trouble, I think mostly because of the spaces in the movie names. I know about `" "', used for quotation marks within strings, but I can't get the macro to work.

I used levelsof and stored the results in a local macro. I then looped through the local variable and concatenated all of the values into a new veritable.

The variable first looked like this: Indiana Jones James Bond Top Gun.

Then I added quotation marks: "Indiana Jones" "James Bond" "Top Gun."

And created a macro to hold all of these.

But I have tried everything and could not loop through that macro. I tried without quotation marks, with quotation marks, and `" "' . Nothing has worked.

There must be a better way in the first place.

Any suggestions?

Thank you.

Renaming names of variables in a stata graph output

$
0
0
Dear Statalisters,

Hello.

I am relatively new to Stata and I am stuck with a small technical problem when creating a graph with marginsplot.
I am plotting my coefficients on a graph as follows;

Code:
*Model1
quietly xtreg x1 x2 x3 x4 x5 x6 x7 x8 x9 x9, fe
quietly margins, dydx(*)
marginsplot, horizontal xline(0) yscale(reverse) recast(scatter) level(90)
The output graph for the above code is attached.

What I want to do is to change the variables names of x1~x9 on the y-axis.
I know I can do this manually, but since I will make many graphs and combine them afterwards, I really hope someone can help me to write a code that will do this.
I cannot change the names of the variables in the actual dataset because I want to rename the variables into Japanese.

Code to run Ordered Logistic Model - using Generalized Estimating Equations (GEE)

$
0
0
Hi everyone !

Im doing a Master's thesis.
My dataset is a panel data. I just wonder How to run Ordered Logistic Model by using GEE estimating method, because almost of Logistic Models under panel data just using Maximum Likelihood Estimating method to estimates the parameters. Is this strange in the study ? If not strange, So what is the code to run the model ?

Thank for your help

Wesley,

Sorting stocks into portfolios then calculate statistics for the next period

$
0
0
Dear Statalist,

I am trying to sort the cross-section of stocks into 5x5 groups, In each period, I want to sort stocks based on their size and then for each size portfolio, sort their respective ownership measure. After that, I want to calculate the average volatility during the quarter for each of the 25 categories and the differences between the highest and lowest quintiles. I have been trying to use foreach command but it kept reporting error 'not sorted'.
My data looks like following:
cusip datetq size ownership IV
1 2010Q1 12 10 0.1
1 2010Q2 13 13 0.2
1 2010Q3 14 14 0.3
1 2010Q4 13 16 0.3
1 2011Q1 15 15 0.2
1 2011Q2 14 14 0.4
2 2010Q1 5 12 0.4
2 2010Q2 6 11 0.4
2 2010Q3 9 10 0.5
2 2010Q4 8 11 0.5
2 2011Q1 7 12 0.6
3 2010Q1 13 11 0.6
3 2010Q2 14 11 0.7
3 2010Q3 13 11 0.7
3 2010Q4 15 11 0.7
3 2011Q1 14 10 0.4
3 2011Q2 5 10 0.4
3 2011Q3 6 10 0.5
4 2010Q1 5 10 0.5
4 2010Q2 6 10 0.6
4 2010Q3 9 9 0.3
4 2010Q4 8 9 0.2
4 2011Q1 7 9 0.4
4 2011Q2 13 13 0.4
5 2010Q1 13 16 0.4
5 2010Q2 15 15 0.5
5 2010Q3 14 12 0.5
5 2010Q4 5 11 0.6
5 2011Q1 6 11 0.3
5 2011Q2 5 11 0.2
Any help is much appreciated.

Viewing all 72898 articles
Browse latest View live


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