Quantcast
Channel: Statistics Help @ Talk Stats Forum - Stata
Viewing all 800 articles
Browse latest View live

Generate a variable based on 3 dummy variables

$
0
0
Hi all,

I have:

HIV
1= Positive
0= Negative

Syphilis
1= Positive
0= Negative

Gonorrhea
1= Positive
0= Negative

I want a to create STI
1=HIV
2=Syphilis
3=Gonnorrhea

I tried:
gen sti=.
replace sti =1 if HIV==1
replace sti =2 if Syphilis ==1
replace sti =3 if Gonnorreha==1

It didnt work.

Help please!

Instrumental Variable Regression (IVREG2)

$
0
0
Hi all

I am looking to create a instrumental variable regression to look at the impact of banking crisis on income inequality (in particular the Gini Coefficient).

I am basing my regression model on http://www3.eeg.uminho.pt/economia/n...WP_30_2011.pdf (I have posted the working paper however it is a published journal article).

I have been trying to recreate the regression using g-7 countries and a slightly different set of variables using the ivreg2 command in stata.

When the paper say "We instrument Gini coefficient index, income per capita
and government size with their lags. Financial depth and unemployment rate are assumed to be exogenous"

What does this relate to in stata code?

Thanks

ajl0411

xttest0 - Breusch & Pagan Lagrangian multiplier test for random effects

$
0
0
hi,

im doing a dissertation on corporate finance. I have run this xttest0 test in stata and posted my results as an attachment. Could anyone tell me how to interpret the results please? i think i have already been told that there are NO random effects but i need to put the relevant variables in a chart and interpret them so what are the variables i am interest in and why..thank you :)
Attached Thumbnails
Click image for larger version

Name:	xttest0.jpg‎
Views:	N/A
Size:	6.9 KB
ID:	3241   Click image for larger version

Name:	xttest0.png‎
Views:	N/A
Size:	7.3 KB
ID:	3242  

Generate variable that shows the question with the highest correct answers

$
0
0
hi friends,

I asked 25 questions in a test.

q1
1=correct
0=incorrect

q2
1=correct
0=incorrect

So on,

I would like to know which of the 25 question has the most correct responses. I could tab each variable and know the answer but is there a way to create a new variable with this info? Perhaps egen, somenthing??
In order words I would like a single table with the frequencies of the 25 variables
new var
q1=12
q2=25
q3=23

so on...



Thank you all in advance!!
Marvin

intra-variable dummy

$
0
0
Hi guys,

my problem is the following: i have a data set that contains info about household (identified by a household ID) and also the people in the household (identified by a personal ID). that means i have one row in stata per person and therefore, the Household ID appears in multiple rows. now i want to create a dummy for a certain piece of info in the household that has been collected on individual basis. that is, i want to know whether this hh has a non-resident member. i have this info on a personal basis (the individuals have a resident/non-resident dummy) and i just want a dummy for all persons- whether they live in a hh with a migrant, yes for every person that does, and 0 otherwise. does anyone have an idea how to do this? thanks.

Mcnemar's test stata

$
0
0
Hi all,

I asked a question in the pre and post test for the same participants. My variable is dichotomous:
1= correct
0= incorrect

I want to see if there is a significant change between pre to post questionnaires. I want to use mcnemar's test. What is the correct way to do this test in stata. My data set look like this:

id q1pre q2pre q3pre q1post q2post q3post
1 1 0 0 1 1 2
2 0 1 1 0 1 1
3 0 0 0 0 1 1

Thank very much I would appreciate it.

Marvin

How to sum observations by month

$
0
0
Hi everyone,
This is probably an easy one for some of you. I have a certain number of events that occur per day, and I want to sum them per month. The variables are date and event, and the date variable is in SIF numeric and formatted as %td.

Any help is appreciated.

Categorical Predictor and Outcome Variables

$
0
0
I’m relatively new to stata and have to undertake some questionnaire analysis.

I’m interested in whether parental type (3 levels) has an influence on A-level achievement (4 levels). What would be the most appropriate analysis for this? My understanding is that I would have to create dummy variables in stata...could anyone advise on the appropriate commands to settle me in please?

Multiple and joint correspondence analysis (MCA) help for graphs

$
0
0
Hi,

Sorry in advance for my English speaking.
I am currently analysing data using a MCA approach with Stata.
Does someone know how to get the individual coordinates on the principal axis?
Does someone have some documents that may help to deal with graphs after MCA?

Thank you in advance for your help.

Valérie

Marginsplot for categorical by categorical interaction with multiply imputed data

$
0
0
Hi all,

I am trying to use marginsplots to graph a categorical by categorical variable interaction between gender (0 1) and level of drug use (0 1 2) for a logit model predicting lifetime sexual partners using multiply imputed data. I used the code from the ATS UCLA website as a template (http://www.ats.ucla.edu/stat/stata/f...arginsplot.htm). However, I'm getting an error when I run it and still being rather new to STATA, I could use some help getting it to run. Here is the output with the error:

program emargins, eclass properties(mi)
version 12
args outcome
logit sexpartner_life i.user female borninus pared age condom drug_sex
margins, at(female=(0 1) user=(0 1 2) atmeans asbalanced ///
post predict(outcome(`outcome'))
end

program myret, rclass
return add
return matrix b = b
return matrix V= V
end

mi estimate, or: logit sexpartner_life i.user female borninus pared age condom drug_sex probuser##female

forvalues i=1/3 {
mi estimate, cmdok: emargins `i'
mat b= e(b_mi)
mat V = e(V_mi)

quietly logit sexpartner_life i.user female borninus pared age condom drug_sex probuser##female if _mi_m == 0
quietly margins, at(female=(0 1) user=(0 1 2)) ///
atmeans asbalanced predict(outcome(`i'))

myret
mata: st_global("e(cmd)", "margins")

marginsplot, x(user) recast(scatter) name(logit`i', replace)

}
an error occurred when mi estimate executed emargins on m=1
r(111);

Any help would be greatly appreciated. Please let me know if more information is needed.

Thanks, O

Calculate residuals after VECM

$
0
0
In the univariate case we can use -predict residual, res- to acquire the residuals after fitting a model. Here's the deal, I cannot find any command that gives me residuals after fitting a VAR or VEC model (i.e. multivariate models). In these models, there are p (number of variables i the model) sets of residuals that can be estimated.

Does anyone know how to get all of the residuals in this case?

Bootstrap sample from only one variable?

$
0
0
Is this possible in STATA? When using the ordinary bootstrap command, STATA draw a bootstrap on all variables.

Constrained Regression! How to impose constraints containing regression coefficients

$
0
0
Hi,

I want to run a constrained linear regression in STATA for the model as follows:

constraint 1 (b1) + (b2) + 2*{(b3)}*log_mpce + (b4) = 0,
cnsreg log_fdexp spi log_mpce log_mpce_sqrd log_nonfd constraint (1)

where b1 = regression coefficient of spi
b2 = regression coefficient of log_mpce
b3 = regression coefficient of log_mpce_sqrd
b4 = regression coefficient of log_nonfd

But every time I run the command it shows:
(note: constraint number 1 caused error r(111))
matrix e(Cns) not found

Please help.
Thanks.

creating a non-smoothed graph of the hazard function

$
0
0
Hi guys! I'm working on a duration model and I'd like to create a graph of the hazard function, but using the command "sts graph haz" I get a smoothed graph while i'd like to show the non-smoothed graph to my professor. Is there anyone that can help me? thanks

Problem converting variable (from string to string)

$
0
0
In order to merge to datasets using a unique ID and a variable specifying time (e.g. 2006Q1) I need to convert a variable in one of the datasets. There time is specified as 31mar2006.

So to do so I use the gen command name this new variable datacqtr so:

gen datacqtr ="2006Q1" to start out with.

subsequently I want to replace 2006Q1 with 2006Q2 according to the time variable, so 2006Q2 if time = 30jun2006. I tried to do that with the command:


. replace datacqtr "2006Q2" if rdate="30jun2006"

But no matter what variation I use of this code (with of without quotation etc.) I always get the error message:

"2006Q2 invalid name
r(198);

datacqtr is a string variable and rdate is a long variable. I've consulted many online articles on generating and converting variables but none were of help. If anyone could give me some pointers on what I'm doing wrong I would much appreciate it.

Cheers,

Robin

Euclidean distance problem

$
0
0
Hey all,

So this should be an easy solution, but for the life of me I cannot think how to get this to work. I need to figure out how to compute the "Cideo" portion of this equation:

Party balancing = |Rideo – Cideo | – |Rideo – (GOPideo-Dideo )/2|, where

Rideo = respondent’s self-placement within ideological space
Dideo = respondent’s placement of Democratic party within ideological space
GOPideo = respondent’s placement of Republican party within ideological space
Cideo = the value of Dideo or GOPideo that most closely approximates the respondents ideological self-placement, Rideo

If anybody can help with writing the code for the Cideo component of this in Stata, I would be forever grateful.

checking proportional hazards assumption with survey data

$
0
0
Hello, I am conducting a survival analysis using survey data in STATA. Does anyone have tips for checking the assumption of proportional hazards using survey data in STATA? It seems that the estat phtest and stphtest commands do not work after svy commands.

Any suggestions?

Thanks,
Alex

Pseudo R² for xtlogit

$
0
0
Hello everybody,

I'm currently working with a logistic panel regression with random effects -xtlogit,re-. While I'm able to calculate pseudo R² for my pooled models -logit, cluster (...)-, I'm not able to calculate these for the -xtlogit, re- model.

Is there a way to calculate these pseudo R²? If not, what other criteria would you use instead?

Thanks a lot in advance!

Reshaping dataset

$
0
0
Hi,

I have a dataset that has the following variables:
date stock1 stock2 stock3 etc. where the stockprices are recorded for each stock at each date for 300 dates. But what I want is to reshape the data in stata such that I get date and then a variable prices where each stock is below one another. So I get the date and then the corresponding prices for stock 1 in row 1-300 and an extra indicator variable with the stock1 etc. For stock 2 I want the prices in row 301-601 and the indicator variable should be stock2 and ofcourse the date should be 1-300 again.

Does anyone know how to do this?

Thanks a lot,

Carmen

NLSY79 Help - Longitudinal data in STATA

$
0
0
Hey, guys.
I'm trying to use the National Longitudinal Survey Year 1979 data set in a multiple regression model. The data set has data from 1979-2010, so there are many years to choose from.
I want to use the depression score collected in Health Module 40 as my independent variable. Basically, when a respondent turned age 40, they were given a depression scale, and the depression score was calculated for them at that age.
Now, let's say I want to use a variable called "exercise frequency" for my dependent variable. Here's where I am running into a problem. Exercise frequency at age 40 was collected over several years (1998-2010, to be exact) because respondents were all different ages when the surveys began in 1979. For example, one respondent may have been age 40 when they answered the exercise frequency item in 1998 whereas another respondent might have been 38. I am only interested in the responses of people who were age 40 at the time the question was asked.
So, how do I write code that will pull the exercise frequency data from years 1998-2010 ONLY if the respondent was age 40 and create a new variable that is "exercise frequency at age 40"?
I'm using STATA, so please comment if you know how to do it in this program.
Thanks! I appreciate your help.
Viewing all 800 articles
Browse latest View live