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

Conducting ttest for pretest and posttest survey using svyset

$
0
0
Hello experts,
I would like to request for your expert help in conducting ttest for pretest and posttest survey using svyset. I have two datasets fro two different surveys - pretest and posttest survey. Prestest with 13000 samples and posttest with 2000 samples; these 2000 samples match with pretest sample. For these, I also have two different weights for presets and posttest. I have merged this two datasets together. I want to do ttest for these two datasets (unpaired) using svyset. For example, considering household size, I have two variables - hhmem (pretest) and b1 (posttest). How to perform ttest or compare mean using svyset? Your support is highly appreciated. Thanking you.





What do the values of -margins- after -stcox- mean?

$
0
0
Dear all,

I'm running a Cox regression model using -stcox-. I'm interested in the effect of one continuous independent variable on the hazard to commit crime.
The coefficient I get for this variable is positive and significant, and I want to illustrate the results using -margins-:

Code:
margins, at(independent_var=(0(0.2)1))
If I understand correctly, what I get from -margins- after -stcox- is the "relative hazard". But this is relative to what?
For example, if I get that 0.8 for a value of 0.5 for the independent variable, what does that mean?

Thanks!

Need help with multivariate regressionanalysis

$
0
0
Hello, as the title suggests I´m struggling with multivariate regressionanalysis. I´m using the data from the ESS, round 9. For an Uni assignment we´re trying to analyse the researchquestion "Does the land one lives in influence their overall life satisfaction" and "Do social contacts further influence the relationship between x and y?"

So we´re using x ("cntry" in the dataset) to try and explain y ("stflife" --> satisfaction) , and control with Z ("sclmeet" -> social contacts).

The professer suggested that we just use a singular country for the analysis, so reduce "cntry" to one observation, but after I´ve done that, Chi - Test and others don´t seem to work anymore.

I´m just trying to do a regression analysis with the three described variables, would be really grateful if someone could help me!


Problem in panel data analysis regarding use of if clause

$
0
0
Hello together,

I am using Stata 16.1 and only had basic training with regressions and so on.
Now I have to do a panel data analysis and try to rebuild a model used in a paper.

In this model an instrumental variable (SSO) signifying an event is introduced that should be 1 if one of my variables (V1) is lower than the average of said variable (AV1). To be precise it must be lower than AV1 minus 2 standard deviations (SDV1) of V1.
This I was able to rebuild with:
replace SSO=1 if V1< AV1-2*SDV1
But now the paper states, that the event should start (meaning SSO=1) as soon as V1 gets below AV1 minus one SD and end as soon as it reaches that threshold again.
So I need to have a command look at the situation “around” my previously determined points of time at which SSO=1
I thought I could use
replace SSO=1 if F1.SSO=1 & V1<AV1-SDV1
replace SSO=1 if L1.SSO=1 & V1<AV1-SDV1
this way I would get all the points right before and after the event and if I would do that again with
replace SSO=1 if F1.SSO=1 & V1<AV1-SDV1 for several times, until no real changes happen, I should be able to catch all of the points I want to have.

However this doesn’t seem to work and I suspected that I couldn’t use “if” and base it on the same variable so I tried gen SSOO=SSO and thought I could work around that problem like this but Stata still won’t let me do it, returning “invalid syntax r(198);”
I suspect that I cant used the F1,L1 with if but I have no idea on how to get the result I want. Do you have any ideas? I don’t seem to be able to exactly define what I want in 1 sentence, which is why I can’t find the answer I need, which is certainly buried in an answer somewhere already. Sorry for that.
Below you can find an example I created with dataex, I hope this helps you help me. Thank you in advance!

[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(country time) float(V2 V1 AV1 SDV1 SSO)
1 114 . . -626284992 541678912 0
1 115 . . -626284992 541678912 0
1 116 . . -626284992 541678912 0
1 117 . . -626284992 541678912 0
1 118 . . -626284992 541678912 0
1 119 . . -626284992 541678912 0
1 120 -16836188160 . -626284992 541678912 0
1 121 -18236448768 -1400260608 -626284992 541678912 0
1 122 -19536486400 -1300037632 -626284992 541678912 0
1 123 -21409628160 -1873141760 -626284992 541678912 1
1 124 -22782924800 -1373296640 -626284992 541678912 0
1 125 -24309022720 -1526097920 -626284992 541678912 0
1 126 -25717108736 -1408086016 -626284992 541678912 0

How to check if IDs before/after one specific date are the same? if not, how do we know which ones are new or which ones dropped out?

$
0
0
Hi everyone,

I would like to know if the (separate) identifiers before and after June 1, 2021 are the same. And if not, I'd like to know which are new or which have been discontinued, please.

I then would like to do a graph (bar, or hbar, or if you think about one more suitable to this, please go ahead with your suggestion!) that shows how many IDs are the same, how many dropped out, and how many jumped in, please.

Here is a dataex:


Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input long(id sp_zipcode) double(date_contract_start date_contract_end) float group
1001  9200 18887 21700 0
1001  9200 21701 22431 0
1001  9200 22432 22645 1
1001  9200 22646 22676 1
1001  9200 22677 22735 1
1001  9200 22736 23010 1
1001  9200 23011 23069 1
1001  9200 23070     . 1
1005 48600 18800 21639 0
1005 48600 21640 21651 0
end
format %td date_contract_start
format %td date_contract_end

-group- is a dummy variable (0/1):

Code:
bys id date_contract_start: gen group = date_contract_start >= mdy(6, 1, 2021)

Thank you very much in advance.
Best,

Michael

Report of Wilcoxon signed rank test

$
0
0
Hello, I think the correct report of WIlcoxon signed-rank test should be like this... "Wilcoxon signed rank test; T =XX ; N = XX; p < 0.05".
But using stata, the output has only z-value and p value.
How should I get the " T " ? ? This may be stupid, but I've tackled this for a few days.
Please help me.

&quot;Variable Calculation Logic in a Dataset: Subtracting 'avg_aar_before' from 'avg_aar_after'&quot;

$
0
0
Hi all

In my dataset, I possess a dataset with observations falling within the range of 1 to 1622 for the variable "sum." Complementing this, I have variables denoted as "switch," "avg_aar_before," and "avg_aar_after." The objective is to compute the subtraction of "avg_aar_before" from "avg_aar_after." To elucidate, when the "sum" variable assumes an even value, it aligns with the "avg_aar_after" value, whereas odd values of the "sum" variable correspond to the "avg_aar_before" value. This pattern persists for all values of "sum" from 1 to 1622, following a simple logic pattern such as (2-1), (4-3), and so forth. The subtraction process is iteratively applied to all dataset entries. Kindly Help with this query


Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input int original_order byte(switch sum) float(avg_aar_before avg_bar_before avg_aar_after avg_bar_after)
  1 . .         .          .         .          .
  2 . .         .          .         .          .
  3 . .         .          .         .          .
  4 . .         .          .         .          .
  5 . .         .          .         .          .
  6 . .         .          .         .          .
  7 . .         .          .         .          .
  8 . .         .          .         .          .
  9 . .         .          .         .          .
 10 . .         .          .         .          .
 11 . .         .          .         .          .
 12 . .         .          .         .          .
 13 . .         .          .         .          .
 14 . .         .          .         .          .
 15 . .         .          .         .          .
 16 . .         .          .         .          .
 17 . .         .          .         .          .
 18 . .         .          .         .          .
 19 . .         .          .         .          .
 20 . .         .          .         .          .
 21 . .         .          .         .          .
 22 . .         .          .         .          .
 23 . .         .          .         .          .
 24 . .         .          .         .          .
 25 . .         .          .         .          .
 26 . .         .          .         .          .
 27 . .         .          .         .          .
 28 . .         .          .         .          .
 29 . .         .          .         .          .
 30 . .         .          .         .          .
 31 . .         .          .         .          .
 32 . .         .          .         .          .
 33 . .         .          .         .          .
 34 1 1 .10350805 .018040802         .          .
 35 . 1         .          .         .          .
 36 . 1         .          .         .          .
 37 . 1         .          .         .          .
 38 . 1         .          .         .          .
 39 . .         .          .         .          .
 40 1 2         .          . .18747446 .022247463
 41 . 2         .          .         .          .
 42 . 2         .          .         .          .
 43 . 2         .          .         .          .
 44 . 2         .          .         .          .
 45 . .         .          .         .          .
 46 . .         .          .         .          .
 47 . .         .          .         .          .
 48 . .         .          .         .          .
 49 . .         .          .         .          .
 50 . .         .          .         .          .
 51 . .         .          .         .          .
 52 . .         .          .         .          .
 53 . .         .          .         .          .
 54 . .         .          .         .          .
 55 . .         .          .         .          .
 56 . .         .          .         .          .
 57 . .         .          .         .          .
 58 . .         .          .         .          .
 59 . .         .          .         .          .
 60 . .         .          .         .          .
 61 . .         .          .         .          .
 62 1 3 .13930307 .030586015         .          .
 63 . 3         .          .         .          .
 64 . 3         .          .         .          .
 65 . 3         .          .         .          .
 66 . 3         .          .         .          .
 67 . .         .          .         .          .
 68 . .         .          .         .          .
 69 1 4         .          . .13479441 .027604437
 70 . 4         .          .         .          .
 71 . 4         .          .         .          .
 72 . 4         .          .         .          .
 73 . 4         .          .         .          .
 74 . .         .          .         .          .
 75 . .         .          .         .          .
 76 . .         .          .         .          .
 77 . .         .          .         .          .
 78 . .         .          .         .          .
 79 . .         .          .         .          .
 80 . .         .          .         .          .
 81 . .         .          .         .          .
 82 . .         .          .         .          .
 83 . .         .          .         .          .
 84 . .         .          .         .          .
 85 . .         .          .         .          .
 86 . .         .          .         .          .
 87 . .         .          .         .          .
 88 . .         .          .         .          .
 89 . .         .          .         .          .
 90 . .         .          .         .          .
 91 . .         .          .         .          .
 92 1 5  .1675365  .02722965         .          .
 93 . 5         .          .         .          .
 94 . 5         .          .         .          .
 95 . 5         .          .         .          .
 96 . 5         .          .         .          .
 97 . .         .          .         .          .
 98 . .         .          .         .          .
 99 1 6         .          . .17935535  .02552348
100 . 6         .          .         .          .
101 . 6         .          .         .          .
102 . 6         .          .         .          .
103 . 6         .          .         .          .
104 . .         .          .         .          .
105 . .         .          .         .          .
106 . .         .          .         .          .
107 . .         .          .         .          .
108 . .         .          .         .          .
109 . .         .          .         .          .
110 . .         .          .         .          .
111 . .         .          .         .          .
112 . .         .          .         .          .
113 . .         .          .         .          .
114 . .         .          .         .          .
115 . .         .          .         .          .
116 . .         .          .         .          .
117 . .         .          .         .          .
118 . .         .          .         .          .
119 1 7 .16191193  .02544296         .          .
120 . 7         .          .         .          .
121 . 7         .          .         .          .
122 . 7         .          .         .          .
123 . 7         .          .         .          .
124 . .         .          .         .          .
125 . .         .          .         .          .
126 1 8         .          .  .1609211  .02792638
127 . 8         .          .         .          .
128 . 8         .          .         .          .
129 . 8         .          .         .          .
130 . 8         .          .         .          .
131 . .         .          .         .          .
132 . .         .          .         .          .
133 . .         .          .         .          .
134 . .         .          .         .          .
135 . .         .          .         .          .
136 . .         .          .         .          .
137 . .         .          .         .          .
138 . .         .          .         .          .
139 . .         .          .         .          .
140 . .         .          .         .          .
141 . .         .          .         .          .
142 . .         .          .         .          .
143 . .         .          .         .          .
144 . .         .          .         .          .
145 . .         .          .         .          .
146 . .         .          .         .          .
147 . .         .          .         .          .
148 . .         .          .         .          .
149 . .         .          .         .          .
150 . .         .          .         .          .
end


teffects with panel data?

$
0
0
I am working with panel data and have used xthdidregress to do a difference in differences analysis using the reservation status of villages in rural India as a `treatment.’ I was considering using teffects as a robustness check for my estimates, and it appears to work with panel data. However, my treatment estimates are wildly different. Is this because teffects only computes an aggregated difference between two groups, and does not take into account the pre-treatment stage? Also, would anyone recommend using teffects with panel data or not?

Thanks for letting me know!

How to generate non-linear moderation plot with confidence intervals after using -xtivreg, fe-

$
0
0
Dear all,

Many thanks for your time.

I am running moderation analyses with panel data, where the independent variable is endogenous and is treated with instruments.

My command looks like this: xtivreg Sales (X1 = Z1) X2 W1 X2*W1 X2*X2 X2*X2*W1 C1 C2 C3, fe

Normally, after xtreg command, we can use the following commands to generate moderation plot, with detailed confidence intervals for each of the X2 effects at different levels of W1, i.e., a spotlight analysis:
margins, at(X2=(0(1)5) W1=(-1 0 1))
marginsplot

However, this approach does not seem applicable to xtivreg command, especially if I am interested in the "X1 is moderated by W2" senario.

If I manually calculate the predicted values of DV against the IV at different levels of W, and generate the moderation plot via "twoway" command, I will not be able to obtain the confidence intervals of the IV.

Can anyone help me on this issue, how to generate non-linear moderation plot with confidence intervals after using -xtivreg, fe-?

Much appreciated for your help.

Best regards,
Chuanqi

Hetero Treatment Effects using IV

$
0
0
Hi all,

I'm trying to determine an equation that I can use to determine if the effect of lagged GDP growth on conflict vary heterogeneously depending on slave exports.

This is what I came up with:

regress any_prio gdp_g_l c.gdp_g_l#c.slave_exports, robust cluster(ccode)

However, I also used lagged rainfall as an IV to determine the effect of GDP growth on conflict:

ivreg2 any_prio (gdp_g_l = GPCP_g_l) $x_covariates i.year i.ccode, robust cluster(ccode)

where,
any_prio = conflict
gdp_g_l = gdp growth lagged
GPCP_g_l = rainfall growth lagged
additional info: I am using panel data of countries in Africa from 1985 - 1999

Is there a way I can keep the IV but then include an interaction to determine if there are heterogeneous treatment effects?

Difference between reg and xtreg

$
0
0
Hello everybody

What is exactly the difference between those two commands?

Thank you in advance

error: r198 - you must use either the timevar() or centile(option).

$
0
0
Hello all,

I am replicating Paul Dickman's do file


Code:
 // age-standardised 5-year survival for males, females, and the difference between the two // the standard population is the age distribution of all patients across all years

generate t10=10 in 1
forvalues y = 2003/2020 {  
display "Calculating age-standardised survival for year: `y' "  
rcsgen, scalar(`y') knots(${yearknots}) rmatrix(R) gen(c) 
standsurv , at1(male 0 maleyr1 0 maleyr2 0 maleyr3 0 yearspl1 `=c1' yearspl2 `=c2' yearspl3 `=c3') ///
at2(male 1 maleyr1 `=c1' maleyr2 `=c2' maleyr3 `=c3' yearspl1 `=c1' yearspl2 `=c2' yearspl3 `=c3') ///              
timevar(t10) contrast(difference) ci ///              
atvar(S_female`y' S_male`y') contrastvars(S_diff`y')
}  


list *1975* in 1
I get the following error:

"you must use either the timevar() or centile() option (or the attime(var) suboption of the (at) option.)
r198

I don't undrestand what this means, or what I'm doing wrong
I literally replciated the code of Paul dickman but instead change the years and instead changed t10=10 in 1

Let me know if you can see anything I;m doing wrong
as i can;t see anything wrong - but perhaps I'm naive !

error: r198 - atvar() option should either give 2 new variable names or use the stub* option. the specified variable(s) probably exists

$
0
0
Hello all,

I am replicating Paul Dickman's do file


Code:
 // age-standardised 5-year survival for males, females, and the difference between the two // the standard population is the age distribution of all patients across all years

generate t10=10 in 1
forvalues y = 2003/2020 {  
display "Calculating age-standardised survival for year: `y' "  
rcsgen, scalar(`y') knots(${yearknots}) rmatrix(R) gen(c)
standsurv , at1(male 0 maleyr1 0 maleyr2 0 maleyr3 0 yearspl1 `=c1' yearspl2 `=c2' yearspl3 `=c3') ///
at2(male 1 maleyr1 `=c1' maleyr2 `=c2' maleyr3 `=c3' yearspl1 `=c1' yearspl2 `=c2' yearspl3 `=c3') ///              
timevar(t10) contrast(difference) ci ///              
atvar(S_female`y' S_male`y') contrastvars(S_diff`y')
}  


list *1975* in 1
I get the following error:

error: r198 - atvar() option should either give 2 new variable names or use the stub* option. the specified variable(s) probably exists

I don't undrestand what this means, or what I'm doing wrong
I literally replciated the code of Paul dickman

I don't have any variables by the name S_male or S_female
I've just got variable male = 1 (where male =1 and male = 0 is female)

Let me know if you can see anything I;m doing wrong
as i can;t see anything wrong - but perhaps I'm naive !

Plot mean of one variable for deciles of another variable

$
0
0
Dear Statalist

I am trying to plot the mean of one variable for each decile of another variable. For example, I have wealth deciles:
Code:
xtile deci = wealth, nq(10)
and the mean ANC visits for women in each decile:
Code:
bysort deci: egen mean_visits = mean(ANC)
I want to visualize the mean number of ANC visits for women in each wealth decile. How would I implement this in Stata?

Thank you for your time and help!

data already long..variable yydx already exists

$
0
0
Hi I'm trying to use Paul Dickman's code

Source:
https://pauldickman.com/software/sta...e-standsurv.do

However when I come to this section
- The only thing I have tweaked is keeping yydx here - as I think it makes sense to keep it as it is then used to reshape

Code:
//reshape from wide to long to make plotting easier
keep in 1
keep id S_male* S_female* S_diff* yydx
reshape long S_male S_male@_lci S_male@_uci S_female S_female@_lci S_female@_uci S_diff S_diff@_lci S_diff@_uci, i(id) j(yydx)

I get the following error

variable yydx already exists
Data are already long.
r(110);

Any thoughts why this is happening?

Coefficient as legend in graph??

$
0
0
Hi!

I there a way to insert a coefficient from the linear regression as legend in a graph? In this case, 0.0309 (rounded with two decimals) and 0.351... from the multivariate regression.

Array

Array

quietly regress Total_CO2 HGB
quietly eststo bivariate: margins, at(HGB=(60(20)200)) post
quietly regress Total_CO2 HGB AGE DATUM i.SEASON
quietly eststo multivariate: margins, at(HGB=(60(20)200)) post
coefplot bivariate multivariate, at ytitle(CO2) xtitle(HGB) ///
recast(line) lwidth(*2)
Array

State-Space Models with Regime Switching

$
0
0
Hello,

I try to estimate a growth model with Markov-switching models with AR(1) with both expansion and recession states. That is two states, expansion and recession.

Mainly the impact of a number of indicators(index1 index2 form1 form2) on the growth rate(gdp_g), for expansion and recession.

The theoretical background is a state space model with a latent unit root; (AR(1)).

All variables in the model are endogenous with a single lag. I saw the help file, but I didn't understand how it is done in state space form, when other endogenous parameters affect it...

One step ahead, prediction should be added in addition to address expectations.

Data sample is below.

Thanks for any help!

Mario

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. For more info, type help dataex
clear
input float(year gdp_g index1 index2 form1 form2)
1980 1.2640425 -1.8494064  -.4919946  .1752619 .8247381
1981       1.2 -1.4651397  -.5348802  .2135585 .7864415
1982 1.9678724 -1.1484452  -.7147316  .3413058 .6586943
1983 1.5117022  1.6252997  1.8567197 .26389787 .7361021
1984  2.570638  2.4657974  2.1658478 .18436745 .8156326
1985  .9210638  3.1889434  2.9895875  .1516645 .8483355
1986  2.248085   5.396011  4.5956273 .19957983 .8004202
1987 1.0723404   3.104351   3.289934 .23287007   .76713
1988 2.2489362  1.2033308  .53224826 .22385173 .7761483
1989 2.1693618   .6751824 -.16877118 .23149644 .7685035
1990 .25382978  .05228972  -.3444368 .27984852 .7201515
1991 -.2125532    .935702   .3012117  .3284199 .6465201
1992   .317234  4.1132245  3.1708634  .3083437  .691594
1993 1.3534043   5.108476  2.5406225 .24354993 .7332776
1994  2.612128   3.425388   1.768389 .23602992 .7400631
1995  3.358936   3.972118  2.3609061 .27747253 .7225274
1996 2.3597872   6.033151   4.661421   .325723  .674277
1997 3.0414894   3.793532   3.347975 .30558395 .6757603
1998  1.793617  3.7508705   3.940954 .29313186 .6818681
1999 1.8717022   2.980336   3.343685 .28042582 .7138736
2000  3.385532   2.734389   1.775652  .2688356 .7311644
2001 2.0512767   .7556655    1.75466  .2554258 .7445742
2002  2.913404   1.386648  2.0334747  .2105769  .789423
2003  3.017021  1.5340753  1.0089021  .1955357 .8044643
2004  3.321915    1.81795   .5531137  .2408904 .7591096
2005 2.6668086 -.29726213  -.7515011  .2480769 .7519231
2006  2.732766  -2.838431 -2.9404194  .2673077 .7326923
2007 2.8740425 -1.5961655 -1.8205668 .26824456 .7317554
2008 .04914893  -1.881141  -3.931049  .2303533 .7696467
2009 -.9074468  -.8101007  -1.919522 .23055235 .7694477
2010  2.887234 -2.2245317 -1.8109186 .29588655 .7041135
2011 1.4131914  -1.431529 -1.4509507  .3009355 .6958717
2012  .9474468 -2.6042926 -3.2060516 .25005552 .7229174
2013 1.3274468  -.8640846 -2.6833265 .20782596 .7834868
2014  .8512766  -.6784925  -2.421195 .22527473 .7747253
2015 2.0059574          .          .         .        .
2016 .59042555          .          .         .        .
2017  1.825532          .          .         .        .
2018  1.508298          .          .         .        .
2019  .9170213          .          .         .        .
2020 1.8051064          .          .         .        .
end

non-binary categorical logistic regression coefficients

$
0
0
I am trying to see indivual category logistic regression coefficients for a class I am in- the class uses SPSS and they are easily seen there. I looked around and found the commands estout and esttab. I love Stata and asked if I could use it instead of having to learn a new program. estout former gives the same coefficients as in the main logit output so doesn't add anything and esttab also no individual category coefficients. Help please and thanks in advance.

Align scale of two y-axis

$
0
0
I am trying hard to alignt the scale of the two Y-Axis but Stata seems to override my instructions. Any hints how I can get the 0 to be one the same vertical height?

Illustrative code, let me know if you want a fake MWE.

Code:
qui sum year
local beg = r(min)
local end = r(max)

# delimit ;
    twoway  (line realGDPpcgrowth year, yaxis(2) yscale(r(-6 6)) ylabel(-6(2)6) ytitle("GDP growth %", axis(2) size(small))) ||
            (line wageGrowth year, yaxis(1) yscale(r(-6 6)) ylabel(-6(2)6) ytitle("Wage growth %", axis(1) size(small))),
            title("") xtitle("") xsc(r(`beg' `end')) xlabel(`beg'(2)`end')
            legend(order(1 "Real GDP per capita growth" 2  "Real wage growth") rows(1));
# delimit cr


Array

Block exogeneity in Bayesian VAR

$
0
0
Dear members of the forum. Does anyone know of a way of imposing block exogeneity in a bayesian VAR in Stata? I have reviewed the documentation on running VARs with the Bayes: var command but cannot find the proper mechanism. I am not looking for the exogenous variables option since, later on, I want to estimate IRFs shocking one of the partially exogenous variables within the block. As far as I understand, this cannot be done with the variables included under the exog() option. I use STATA 17. Thanks in advance for any help.
Viewing all 65044 articles
Browse latest View live


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