Thursday, February 28, 2019

Rename variables to remove part of the text

Dear Statalists,

I have the following variables and would like to rename them to remove untitled### from the name. Please help me do this.

untitled108set_number untitled108quest_number untitled108village untitled108house_number untitled108interviewer untitled108int_date untitled108supervisor untitled108time_begin untitled2hh_electricity untitled2hh_solar untitled2hh_radio untitled2hh_television untitled2hh_sofa untitled2hh_cupboard untitled2hh_phone untitled2hh_mobile untitled2hh_computer untitled2hh_table untitled2hh_clock untitled19literacy untitled19marital_status untitled19num_preg untitled19num_livebirth untitled20child_sex untitled20child_dob untitled20child_age grp_vacccarduntitled126bcg_dat grp_vacccarduntitled126bcg_nod grp_vacccarduntitled127polio_d grp_vacccarduntitled127polio_n grp_vacccarduntitled128polio1_ bf grp_vacccarduntitled129polio2_ bi grp_vacccarduntitled130polio3_ bl grp_vacccarduntitled131dpt1_da grp_vacccarduntitled131dpt1_no grp_vacccarduntitled132dpt2_da grp_vacccarduntitled132dpt2_no grp_vacccarduntitled133dpt3_da grp_vacccarduntitled133dpt3_no grp_vacccarduntitled134measles bx grp_vacccarduntitled135yfever_ ca grp_vacccarduntitled136vita_da grp_vacccarduntitled136vita_no grp_vacccarduntitled137pcoccal cg grp_vacccarduntitled138rota_da grp_vacccarduntitled138rota_no untitled118chvact_homevisit untitled118chvact_mchcounsel untitled118chvact_refillness untitled118chvact_refanc untitled118chvact_refdel untitled118chvact_refpnc untitled118chvact_bf untitled118chvact_measure untitled118chvact_other untitled105untitled123chvhome_

Regards,
Christian

Betareg

Hi all,

I have a propotion dependent variable that’s greater than zero and less then one. The mean is 0.1240891 and SD 0.1363 and its positivly skewed. All the independent variables are dummy variables. I have read that betareg is most appropriate model for propotion data.
Want to check did I use the right model and also do I need to check any assumptions before carrying betareg ?

Betareg dep i.var1 i.var2 i.var3 i.var4
margins dep

After running estat ic to check the model fit AIC and BIC are approx -4400

Thank you in advance.

ivreg, ivprobit and biprobit which one to use? (any theoretical reasoning?)

As I do not have any econometric background I find it difficult to understand which one to use when outcomes differ a lot. My dependent (female labor-force participation status), independent (has more than three children) and instrumental (combination of gender of first two children) variables are all binary. OLS, logit, and probit models all have shown similar results (as mentioned in "Mostly harmless econometric" when it comes to average marginal effect there is no difference between these models). But when I run ivreg (2SLS), ivprobit, and biprobit results are totally different. Previous literature just simply use OLS and 2SLS, but I can not find convincing solid reason behind it. (I checked "Mostly harmless econometrics" by Angrist and "Econometric analysis of cross section and panel data" 2nd edition by Wooldridge where explanations were quite vague) What are the trade-off between these models, and how to interpret difference in estimations and how to choose right one?

Question spmap

Hi,

I have a question about spmap. I'm just a beginner with STATA and I want to know how to use spmap for dummy variables.
In my example I want to map the dummy variable ethnicity (1= native & 0= not native) in de resort Paramaribo (capital of Suriname)

These are the steps (my do-file)

spmap mean_etn2 using "Paramaribo_ressort_coord.dta", id(Suriname_ressort_ID) ///
fcolor(Blues) osize(vvthin ..) ///
title("Ethnicity in Paramaribo(adm. level ressort)")

spmap mean_etn2 using "Paramaribo_ressort_coord.dta", id(Suriname_ressort_ID) ///
fcolor(Blues) osize(vvthin ..) ///
title("
Ethnicity
in Paramaribo(adm. level ressort)") ///
clmethod(custom) clbreak(0 1 2)

Now I want to know what the 0, 1 & 2 mean after clbreak and how I can label the legend.
Thanks in advance!

renaming using loop

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str43 Q2_8a1 double(Q2_8b1 Q2_8c1 Q2_8d1 Q2_8e1) str43 Q2_8a2    double(Q2_8b2    Q2_8c2    Q2_8d2    Q2_8e2)    str43    Q2_8a3    double(Q2_8b3    Q2_8c3    Q2_8d3    Q2_8e3)
"anil mongar"        24 1 10 1 "" . . . . "" . . . .
"Nir mala"           34 2 21 1 "" . . . . "" . . . .
"Suk mith lepcha"    64 2 21 1 "" . . . . "" . . . .
"pemba lepcha"       50 1  3 1 "" . . . . "" . . . .
"sangay tenzin"      77 1  8 1 "" . . . . "" . . . .
"Nar Badhur"         32 1  7 1 "" . . . . "" . . . .
"Pema Wangmo Lepcha" 29 2  5 1 "" . . . . "" . . . .
"neelam"             40 2 12 2 "" . . . . "" . . . .
"tandin bida"        43 2 10 1 "" . . . . "" . . . .
""                    . .  . . "" . . . . "" . . . .
"Durga"              31 1  8 1 "" . . . . "" . . . .
"nim dem"            23 2 12 1 "" . . . . "" . . . .
""                    . .  . . "" . . . . "" . . . .
"Namgay Dem"         32 2  8 1 "" . . . . "" . . . .
"kumari tamang"      41 1 21 1 "" . . . . "" . . . .
"Phuntsho wangdi"    48 1  9 1 "" . . . . "" . . . .
"Chungku"            27 2  2 1 "" . . . . "" . . . .
"Deoraj Gurung"      43 1 17 1 "" . . . . "" . . . .
""                    . .  . . "" . . . . "" . . . .
"ganga maya ghally"  45 2 21 1 "" . . . . "" . . . .
end
label values Q2_8c1 Q2_8c
label values Q2_8c2 Q2_8c
label values Q2_8c3 Q2_8c
label def Q2_8c 1 "Male", modify
label def Q2_8c 2 "Female", modify
label values Q2_8d1 Q2_8d
label values Q2_8d2 Q2_8d
label values Q2_8d3 Q2_8d
label def Q2_8d 2 "Grade 2", modify
label def Q2_8d 3 "Grade 3", modify
label def Q2_8d 5 "Grade 5", modify
label def Q2_8d 7 "Grade 7", modify
label def Q2_8d 8 "Grade 8", modify
label def Q2_8d 9 "Grade 9", modify
label def Q2_8d 10 "Grade 10", modify
label def Q2_8d 12 "Grade 12", modify
label def Q2_8d 17 "Bachelor's degree", modify
label def Q2_8d 21 "No education", modify
label values Q2_8e1 Q2_8e
label values Q2_8e2 Q2_8e
label values Q2_8e3 Q2_8e
label def Q2_8e 1 "Bhutanese", modify
label def Q2_8e 2 "Indian", modify
Dear All
How can i use loop to rename all variables from Q2_8a as name1,Q2_8b as age1 Q8_8c as sex1 Q8_8d as edu_level1 and Q8_8e nationaliy1 ajnd simultaneously name2, age2, sex2, edu2, nationality2

creating a variable that takes a value of the difference of the last non-missing value and the first non-missing value in panel data

i have panel time series.
I want to create a variable that is the difference between the last non-missing value and the first non-missing value.so in this case for Austria, the value would be -1 - 0 = "-1".
I want to know the simplest code. I have been creating a variable that is the last value, and another variable that's the first value, and blah blah but i need to do this for so many variables, so i would that'd be a one liner command or something?

thank you!

Binscatter2 - faster, enhanced binned scatterplots in Stata

Hi all,

I wanted to make note of a program that I've had available on GitHub for a while now to generate binned scatterplots in Stata, like Michael Stepner's excellent -binscatter- package. Binscatter2 inherits all of the usage and syntax of binscatter, but runs substantially faster in large datasets by leveraging the functionality of -gtools-. Furthermore, binscatter2 offers a handful of new bells and whistles -- expanded options for saving, fit lines, plotting quantile intervals of the data, etc.

This project is still very much ongoing, and I hope to submit it to SSC very soon.

You can read more it here: https://github.com/mdroste/stata-binscatter2

How does one put formatted date labels into excel with Putexcel?*

Hi there,

Here's my code:


local vars "date"

foreach pre in `vars'{
putexcel set "tabout/cleaningtest_`pre'.xls", replace
putexcel A1="`pre'" A3=("Sample/Patient Characteristic") B3=("Mean (SD)")
tab `pre', matrow(hnames)
local hlevels = rowsof(hnames)
forvalues i = 1/`hlevels' {
local hal`i' = hnames[`i',1]
local hal_lab`i' : label (`pre') `hal`i''
local x = `i' +2
excelcol `x'
putexcel `r(column)'3=("`hal_lab`i''"),

My aim is to put a series of dates in the colums in the excel spreadsheet. It works perfectly except it the dates are in numeric form and not formatted as they are displayed in Stata.

I am using Stata 14.2

Many thanks in advance.

Extracting a specific part of a string if the string contains an exact syntax

OK, so I'm not explaining this very well but here is what I want to do. I have data as shown below.

The incentive has a maximum of $6000.00, The incentive has a maximum of 5.00 Years
The incentive is 0.48 $/kWh
The incentive is 0.60 $/W, The system size has a minimum of 150.00 kW, The system size has a maximum of 200.00 kW
The incentive is 100.00 %
The incentive is 25.00 %, The incentive has a maximum of $1000.00
The system size has a maximum of 50.00 kW, The incentive is 1.05 $/W


What I want to do is extract, for example, if there is a section of the string that contains "The incentive is (NUMBER I WANT TO EXTRACT) $/kWh", I want to extract that number and generate a new variable with it.

So for example, for the sample data above, I want the following output

The incentive has a maximum of $6000.00, The incentive has a maximum of 5.00 Years .
The incentive is 0.48 $/kWh 0.48
The incentive is 0.60 $/W, The system size has a minimum of 150.00 kW, The system size has a maximum of 200.00 kW 0.60
The incentive is 100.00 % .
The incentive is 25.00 %, The incentive has a maximum of $1000.00 .
The system size has a maximum of 50.00 kW, The incentive is 1.05 $/W .


I've read string help, but I'm still struggling with this code.

Thank you so much for all the help in advance.

Proportional odd assumption for ordered logit regression in panel data

Respected sir, I am using xtologit command for ordered logit regression for panel data. My dependent variable has three categories. I want to check proportional odds assumption. I have tried a lot but couldn't get right command. Please help me..
Thank you
Priya

How to solve autocorrelation and hetero ?

I using xtserial and xttest3
What should I do to deal with autocorrelation and hetero ?
My data have 9 countries and 10-40 quarters ( T > N )

a new variable based on two existing variables

Hi,

I'm using SHARE dataset where there is a dummy variable for people having played chess/cards in the previous year (ac035d10) and another one for people having played sudoku/puzzles in the previous year (ac035d9).
I want to generate a new dummy variable "edu_inf" (people involved in informal learning activities in the previous year) based on the two existing variables.
Obviously some people could have played both chess/cards and sudoku/puzzles in the previous year.
How can I generate in STATA this new variable?



Simple loop question

Dear Listers,

I would like to ask you a very simple question regarding loop.

I want to make a variable for each of countries listed in my data. As there are many items, I would like to automate this process by using loop function.

Code:
global X 1 2 3 4 5 6 7 8 9 10 11 

foreach x of global X {

foreach y in 22.26    33.98    16.6    30.16    21.06    11.36    36.29    46.28    64.31    110.56    36.83 {



gen unit_physio_`x'= `y'

}
}

This is my code. In fact what I want is unit_physio_1 = 22.36, unit_physio_2=33.98, unit_physio_3=16.6

However, all of them are 22.26 after I run this code.

I would be happy if someone helps me with this problem.

Many thanks in advance.

Kind regards,

kim

How to recode data with multiple groups

Hi Everyone,

I am fairly new to stata and I am looking at cancer data. I have histology groupings for lung cancer. The groups all over the place so it is hard to include ranges but I included them where I could. The code works perfect but it just seems long and messy. I am looking for a way to make this code more efficient. I apologize in advance if this is an easy fix and Thanks in advance for any help!


recode HistologicTypeICDO3 (8051/8052 =0) (8070/8076=0) (8078 =0) (8083/8084 =0) (8090 =0) (8094 =0) (8120 =0) (8123 =0) (8002 =1) (8041/8045 =1) (8015 =2) (8050 =2) (8140/8141 =2) (8143/8145 =2) (8147 =2) (8190 =2) (8201 =2) (8211 =2) (8250/8255 =2) (8260 =2) (8290 =2) (8310 =2) (8320 =2) (8323 =2) (8333 =2) (8401 =2) (8440 =2) (8470/8471 =2) (8480/8481 =2) (8490 =2) (8503 =2) (8507 =2) (8550 =2) (8570/8572 =2) (8574 =2) (8576 =2) (8012/8014 =3) (8021 =3) (8034 =3) (8082 =3) (8003/8004 =4) (8022 =4) (8030/8033 =4) (8035 =4) (8200 =4) (8240/8241 =4) (8243/8246 =4) (8249 =4) (8430 =4) (8525 =4) (8560 =4) (8562 =4) (8575 =4) (8000/8001 =5) (8010 =5) (8005 =5) (8011 =5) (8020 =5) (8046 =5) (8095 =5) (8124 =5) (8130 =5) (8146 =5) (8160 =5) (8170 =5) (8230/8231 =5) (8247 =5) (8263 =5) (8312 =5) (8340/8341 =5) (8350 =5) (8370 =5) (8441 =5) (8460 =5) (8500/8501 =5) (8510 =5) (8524 =5) (8530 =5) (8551 =5) (8580/9999 =5) ,gen (Histologygroup)
label define Histologygroup 0 "Squamous Cell Carcinoma" 1 "Small Cell Carcinoma" 2 "Adenocarcinoma" 3 "Large Cell Carcinoma" 4 "Other Specified Carcinoma" 5 "Unspecified Carcinoma"
label values Histologygroup Histologygroup

Calandra

dummy for panel data

Hi,
how to create dummy variable for panel data? I want to create a dummy for 130 districts for 3 years; 2010, 2012 and 2014. If the district has a cant then it should be 1 otherwise 0. How to do it for all 3 years?

Issues with Hausman-Wu test

Hi everyone,

I am having issues with running a Hausman-Wu test. The output is as follows:

"hausman fe re

Note: the rank of the differenced variance matrix (8) does not equal the number of
coefficients being tested (9); be sure this is what you expect, or there may be
problems computing the test. Examine the output of your estimators for anything
unexpected and possibly consider scaling your variables so that the coefficients
are on a similar scale.

---- Coefficients ----
| (b) (B) (b-B) sqrt(diag(V_b-V_B))
| fe re Difference S.E.
-------------+----------------------------------------------------------------
Dependency | .0625601 .0869425 -.0243824 .
MilExpGDP | -.1617947 -.0907287 -.071066 .195339
Population | -8.84e-09 3.13e-08 -4.01e-08 3.77e-08
Secondary | -.0252826 -.0201809 -.0051017 .
Unemployment | .0036028 -.009116 .0127187 .0101393
TradeGDP | .0032786 .0063996 -.0031209 .0018899
GDPpc | -3.08e-06 -.0000964 .0000933 .0000417
Inflation | -.0016078 -.0028157 .001208 .
UrbanPop | .2251216 .1224237 .102698 .0358208
------------------------------------------------------------------------------
b = consistent under Ho and Ha; obtained from xtreg
B = inconsistent under Ha, efficient under Ho; obtained from xtreg

Test: Ho: difference in coefficients not systematic

chi2(8) = (b-B)'[(V_b-V_B)^(-1)](b-B)
= 33.87
Prob>chi2 = 0.0000
(V_b-V_B is not positive definite)"

I have already tried different syntaxes, and with sigmamore & sigmaless addition, but these have been to no avail.

Any guidance you could provide on the matter would be gratefully appreciated.

Yours,
Scott

Local macro list and tuples

I am in need of two different tuples lists, so I would like to store one set as a local and call the other in a different loop.

Below is the command i am trying to store. I do not think it is storing the list because when I call the new local list in the second loop it does not recognize the local macro sp`i'. I am trying the following command to store the tuples (tuple1, tuple2, tuple3,...) to sp`i' (eg. sp1, sp2, sp3...) .

tuples x y z w

forval i =1/15 {
local sp`i' `tuple`i''
}

As a bonus question is there a command to count the number of tuples created so I can make the indexing more flexible? So instead of 15 it would be max(tuples), or something similar.
Thanks!

[Tuples is a really cool command. Thanks whoever created it!!!]

Help on modelling- endogeneity-panel data

Hello,

I am running a model to find the effect of corurption on GDP in across Italian regions using panel data. I have found endogeneity between corruption and GDP growth,hence I am trying to use either fixed effects with instrumental variables or OLS with dummy variables.

As for the first case, I am having difficulties when specifying the following:

--> specification 1:
GDP growth= population growth + human capital + public investment + Corruption + Corruption ^2 + log of the lagged GDP pro capite

My coding is:
xtivreg Ygrowth I H logYlevel_1 n (Cor Cor2=Cor_1 Cor_12),fe vce (robust)
where Cor2=Cor^2 and Cor_12=(Cor_1)^2
- however, STATA says that Cor^2 is omitted because of collinearity. why is that the case?


--> specification 2:
GDP growth= population growth + human capital + public investment + logCorruption + log of the lagged GDP pro capite

My coding is:
xtivreg Ygrowth I H logYlevel_1 n (logCor= logCor_1 ),fe vce (robust)
- however, this results in everything being insignificant although I had found the following specification to be significant: xtivreg Ygrowth I H logYlevel_1 n (Cor= Cor_1 ),fe vce (robust)

--> model 2:
I wanted to try the following: reg Ygrowth H logYlevel_1 n I i.Region##c.Cor##i.Year, but it gives me an error message saying I have not coded this right. How do I code a dummy interaction variable to know the effect of corruption for each region for each year?



Joining datasets when a variable is in a different format

Hi all,

I currently have a data set that looks like this where each quarter is represented by a seperate variable and contains values of trade balances (simple values have been put in for example)
naic year q1 q2 q3 q4
321111 1997 5 9 4 2
393333 1998 4 10 4 1
I want to join this with a data set that contains the same naic numbers and the same years but quarter is its own variable (this set contains other variables of industry characteristics- M Y and K)
naic year M Y K qtr
321111 1997 46 45 55 1
321111 1997 29 45 44 2
321111 1997 34 54 75 3
321111 1997 23 34 53 4
321111 1998 54 44 43 1
I want to join these data sets, preferably so the first takes the form of the second with qtr as one variable taking on the sequence of values 1 2 3 4 (essentially want the last 4 columns of the first table to be in one column and hence to expand the observations for each naic code by 4 whilst keeping the values for each quarter)



Report estimates from Heckman AND margins command

Dear all,
I am using Stata 14 and have some questions regarding the commands -Heckman-, -margins- and -outreg2-.

I am trying to produce tables of my regression results using outreg2.
I am running Stata's Heckman and margins command, using following code:

Code:
 heckman y1 `heckvarlist', ///
select(sel=`probvarlist') vce(cluster id) first

margins, dydx(`heckvarlist') predict(ycond) atmean post
outreg2 using "myfile.xls", append ctitle(dy/dx Second stage pooled Heckman) dec(3)
However, I would like my output table to include estimates from the original regression, and not just the marginal effects. I read up on Outreg2 and understand that it's possible to create local macros after running -Heckman- in order to store estimates of e.g. lambda and rho, and include it in the outreg2 output using the addstat command, according to:

Code:
heckman y1 `heckvarlist', ///
select(sel=`probvarlist') vce(cluster id) first

local Lambda=e(lambda)
local Selambda=e(selambda)
local rho=e(rho)

outreg2 using "myfile.xls", adds(Lambda, `Lambda', Selambda, `Selambda', rho, `rho') append ctitle(dy/dx Second stage pooled Heckman) dec(3)
Which makes the output look like:


HTML Code:
 VARIABLES    dy/dx Second stage pooled Heckman    
x1    0.712***    
      (0.029)    
x2    0.239***    
      (0.067)    
x3   0.201***    
     (0.063)    
x4    -0.619***    
    (0.158)    
x5    0.362***    
    (0.140)    
x6    0.028    
    (0.033)    
        
Observations    3,480      
Lambda         -4.405    
Selambda        0.512    
rho            -0.615        
Standard errors in parentheses *** p<0.01, ** p<0.05, * p<0.1


However, I would also like to display the standard error of rho, which is displayed at the bottom of the output table after Heckman, i.e.:
HTML Code:
       _cons |   2.610507   .8621316     3.03   0.002     .9207605    4.300254
-------------+----------------------------------------------------------------
     /athrho |  -.7173276   .0944943    -7.59   0.000     -.902533   -.5321223
    /lnsigma |   1.968422   .0338867    58.09   0.000     1.902005    2.034839
-------------+----------------------------------------------------------------
         rho |  -.6152512    .058725                      -.717529   -.4870017
       sigma |   7.159369   .2426076                      6.699314    7.651017
      lambda |  -4.404811   .5117772                     -5.407875   -3.401746
------------------------------------------------------------------------------
Wald test of indep. eqns. (rho = 0): chi2(1) =    57.63   Prob > chi2 = 0.0000
In the Stata help file on Heckman, I can't find that estimate stored, though. Does anyone know if it is possible to write a command for including it in the outreg2? I know from the helpfile that the standard error of rho is computed using the delta method, does that help me in any way?

Best regards,

Hanna Lindström


Help with reshape

Hello everyone,

I have got the following matrix.

* Example generated by -dataex-. To install: ssc install dataex
clear
input int(isin year) str3(last_name_0 last_name_1 last_name_2 last_name_3 last_name_4 last_name_5 last_name_6 last_name_7 last_name_8 last_name_9)
16 2006 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2007 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2008 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2009 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2010 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2011 "" "LMR" "LMR" "LMR" "" "" "" "" "" ""
16 2012 "" "LMR" "LMR" "" " " " " "" "" "" ""
16 2013 "" "LMR" "LMR" "" " " " " "" "" "" ""
end

I would like to reshape observations per isin and year such as the output after the reshape looks as follows.
isin year last_name
16 2006 LMR
16 2006 LMR
16 2006 LMR
16 2007 LMR
16 2007 LMR
16 2007 LMR
16 2008 LMR
16 2008 LMR
16 2008 LMR
16 2009 LMR
16 2009 LMR
16 2009 LMR
16 2010 LMR
16 2010 LMR
16 2010 LMR
16 2011 LMR
16 2011 LMR
16 2011 LMR
16 2012 LMR
16 2012 LMR
16 2013 LMR
16 2013 LMR
Can you please help me on this matter?
Thank you very much,
Gianfranco

reshape in Stata

Dear All,
I have some issues about reshape. Here is the original matrix I have.

Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int(isin year) str3(last_name_0 last_name_1 last_name_2 last_name_3 last_name_4 last_name_5 last_name_6 last_name_7 last_name_8 last_name_9) 16 2006 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2007 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2008 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2009 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2010 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2011 "" "LMR" "LMR" "LMR" "" "" "" "" "" "" 16 2012 "" "LMR" "LMR" "" "" "" "" "" "" "" 16 2013 "" "LMR" "LMR" "" "" "" "" "" "" "" end format %ty year
Now, I would like to reshape it as follows:
isin year last_name
16 2006 LMR
16 2006 LMR
16 2006 LMR
16 2007 LMR
16 2007 LMR
16 2007 LMR
16 2008 LMR
16 2008 LMR
16 2008 LMR
16 2009 LMR
16 2009 LMR
16 2009 LMR
16 2010 LMR
16 2010 LMR
16 2010 LMR
16 2011 LMR
16 2011 LMR
16 2011 LMR
16 2012 LMR
16 2012 LMR
16 2013 LMR
16 2013 LMR
Any help would be immensely appreciated.
Thank you so much,
Gianfranco

Question about Goodness of fit result

Hi,
I am running a SEM model on Stata. I've 5 IVs, 1 mediator, and DV. with the sample size of 400. And I obtained this result, do you think it is acceptable, if not, what could be the cause and what could be done to obtain a better result.
----------------------------------------------------------------------------
Fit statistic | Value Description
---------------------+------------------------------------------------------
Likelihood ratio |
chi2_ms(162) | 1319.798 model vs. saturated
p > chi2 | 0.000
chi2_bs(190) | 6373.000 baseline vs. saturated
p > chi2 | 0.000
---------------------+------------------------------------------------------
Population error |
RMSEA | 0.134 Root mean squared error of approximation
90% CI, lower bound | 0.127
upper bound | 0.140
pclose | 0.000 Probability RMSEA <= 0.05
---------------------+------------------------------------------------------
Information criteria |
AIC | 20991.679 Akaike's information criterion
BIC | 21263.099 Bayesian information criterion
---------------------+------------------------------------------------------
Baseline comparison |
CFI | 0.813 Comparative fit index
TLI | 0.780 Tucker-Lewis index
---------------------+------------------------------------------------------
Size of residuals |
SRMR | 0.346 Standardized root mean squared residual
CD | 1.000 Coefficient of determination


Thank you for your time!

VISUA Dialog programming GUI

I have seen the presentation on the below link, they have used a VISUA GUI for creating Stata Dialog boxes and survey plugin for data entry. Is there anybody know from where I can get/download VISUA software.

http://docplayer.net/28390582-Advanc...f-palermo.html

Thanks & best regards,
Rasool Bux

Converting string to date/time variables fails somehow

Hello Statalist community, I am struggeling with converting a string containing date and time information inti SIF/HRF. It seems that the seconds aren't converted corrctly. Maybe I am mistaken and use the wrong commands to perform my transformation or maybe the error lies in the wrong display format. As far as I know, I tried all i cound trying to get the right results but actually I failed.

Please can you help me to get the transformation right?

Original string information:

Code:
. describe treatmenttime

              storage   display    value
variable name   type    format     label      variable label
-----------------------------------------------------------------------------
treatmenttime   str19   %19s                  Treatment Time


. list treatmenttime in 1

     +---------------------+
     |       treatmenttime |
     |---------------------|
  1. | 2018-10-10 17:27:14 |
     +---------------------+
Transformation attempt string --> SIF:

Code:
gen treatmenttime2= Clock(treatmenttime, "YMDhms")

. describe treatmenttime2

              storage   display    value
variable name   type    format     label      variable label
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
treatmenttime2  float   %9.0g   

. list treatmenttime2 in 1

     +----------+
     | treatm~2 |
     |----------|
  1. | 1.85e+12 |
     +----------+


. format treatmenttime2 %tC

. list treatmenttime2 in 1

     +--------------------+
     |     treatmenttime2 |
     |--------------------|
  1. | 10oct2018 17:27:21 |
     +--------------------+
So you see: I started with:

2018-10-10 17:27:14

and got

10oct2018 17:27:21

after the transformation.

Furthermore, the actual difference between starting time and transformed time varies depending on the very content of the string between few seconds and minutes which is even more frustrating.

Problem with importing excel on new MacBook

Hi,

I recently started working on a new MacBook from my old MacBook (i.e. I transferred all files, and am now using the new MacBook, Stata 12 on both devices). The Do-files were working perfectly fine on my old Mac, and are also working fine on my new Mac. However, one of my Do-files start with importing an Excel file. When I move the Excel file in question from my old Mac to my new one, and I do not open the file in Microsoft Excel (2016) first, the Excel file can be imported and the Do-file works perfectly fine. However, when I first open the file on my new Mac (regardless of whether I make any changes) I would get the following error:
Code:
. * Import Data:
. import excel "/Users/Rob/Documents/PhD Exercise Science/3. Data/Data_list_statalist.xlsx", sheet("All_data") clear
file /Users/Rob/Documents/PhD Exercise Science/3. Data/Data_list_statalist.xlsx could not be loaded
r(603);
I have attached the excel spreadsheet that is not working (i.e. after I opened and saved it on my new MacBook).

Can anyone reproduce this error, and is there a solution?

Another piece of information that may be important is that on my Old Mac I used MS Word 2011, and on my new Mac I use MS Word 365 (2019?).

Thanks so much.

Problem with graph combine

Hello, I am trying to combine some graphs. I generate the graphs and save them into a folder.
When I try to combine them Stata returns error and says the path of the graph is not found. However, this graph file exists.

This is the code I use to generate the graphs (it works):
Code:
 *GRAPHS*
 foreach a in e ef {
 foreach b in t1m t3m t6m t1y t2y t3y t5y t7y t10y {
 foreach c in mp1 mp2 mp3 mp4 ff1 ff2 ff3 ff4 ed1 ed2 ed3 ed4 {
  twoway  (line ffr_shock date) (line mp_shock date ) (line  `a'_`b'_`c' date) (line ffr_shadow date, yaxis(2)), title("SHOCK:`a'_`b'_`c'", color(black) size(medium))
  graph save  "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'.gph", replace
 }
 }
 }
This is the code I am using to combine graphs (returns error, file not found (but i check it exists))
Code:
 foreach a in e ef {
 foreach b in t1m t3m t6m t1y t2y t3y t5y t7y t10y {
 foreach c in ed mp ff  {
 graph combine "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'1.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'2.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'3.gph" "\\Cntdat08\grp5$\ses\Generi\GENERAL\INVESTIGACION\2018_MP_flows\data\shock\_`a'_`b'_`c'4.gph"
 }
 }
 }

Time Series Regression

Hello,

I am looking at logreturns of two different stock market indices in two countries and seeing if the weather (Cloud, temp, humidity, rain) affects the returns in two countries (two different indices). I am using daily data from 1993-2017.
Therefore I have cross sectional timeseries data. I will be using a GARCH regression, but some of the questions below aren't related to only garch (see q1 and 2 and 8).
One country's data is on top of the others and I identified it as cross sectional by using:

bys country: gen time=_n
xtset country time

I have a few questions I would really appreciate help with

1) Firstly, what does it mean to include a lagged variable, how would I choose it?
2) How do i know whether to include a squared variable and again, how do i choose it?
3) How do I test for how many GARCH lags to use?
4) How do i look at volatility in a garch model?
5) How can I include interactive factor(dummy) variables in the regression?
6) Do i test the errors and residuals, and if so how?
7) how do i test for serial correlation and what does this even show?
8) as i have two regressions per country (pre shock and post shock), how would I show these results on one table?

Please help, I would appreciate any help I am so lost and stuck. If it helps i can send you my data/do file somehow, but otherwise just instructions on which commands is something I would be eternally grateful for.

THANK YOU SO MUCH

I am so desperate lol x

Garch model regression

Hello,

I am looking at logreturns of two different stock market indices in two countries and seeing if the weather (Cloud, temp, humidity, rain) affects the returns in two countries (two different indices). Therefore I have cross sectional timeseries data. One country's data is on top of the others and I identified it as cross sectional by using:

bys country: gen time=_n
xtset country time

I have a few questions I would really appreciate help with

1) Firstly, what does it mean to include a lagged variable, how would I choose it?
2) How do i know whether to include a squared variable and again, how do i choose it?
3) How do I test for how many GARCH lags to use?
4) How do i look at volatility in a garch model?
5) How can I include interactive factor(dummy) variables in the regression?
6) Do i test the errors and residuals, and if so how?
7) how do i test for serial correlation and what does this even show?
8) as i have two regressions per country (pre shock and post shock), how would I show these results on one table?

Please help, I would appreciate any help I am so lost and stuck. If it helps i can send you my data/do file somehow, but otherwise just instructions on which commands is something I would be eternally grateful for.

THANK YOU SO MUCH

I am so desperate lol x


Wednesday, February 27, 2019

How to destring date variable formatted as year and week number

Dear Statalist,

I was just wondering if there is an easy way to destring a date variable formatted as "year and week number".
for example,

2008w34
2008w35
2008w36
2008w37
2008w38


Thanks so much for your help!

Yonatan

IVREG LIML yields zero cefficients and p-value=1.

I am using Stata to run "IVREG LIML" which is an IV with Limited Maximum Likelihood estimator. However, some of the coefficients are zeros with p-value equal 1. I wonder what causes this issue. I really appreciate it if anyone can help me with this problem.

Thank you!

Array

Page break in PDF output

I need to put page breaks in PDF strategically to keep certain lines of text together on the same page.
Is there any way to measure the 'fit' of the text, to determine whether the next line still fits the page or I need to move it to the next page?

Thank you, Sergiy

importing multiple excel files using a loop

Hi statalists, I have the following code but I always get the error message

local dpto AMAZONAS ANCASH APURIMAC
foreach x in local dpto {
import excel using "Z:\HigherEducation_Inequality\INEI\`x'_t.xls" , sheet(`x') clear
keep A B C
keep if A=="18"|A=="19"
xpose,clear
drop in 1
rename v1 pob18
rename v2 pob19
gen Name=`x'
gen id=_n
gen Year=1998 if id==1
replace Year=1999 if id==2
drop id
save data_`x',replace
}

file Z:/HigherEducation_Inequality/INEI`x'_t.xls not found
r(601);


Does anyone has any thoughts about what am I doing wrong?


How to get the quintile points in survey data?

I am using a survey data now and trying very hard to figure out the quintile points (20%, 40%, 60%, 80%) of a continuous variable.
I know the code to get the quartile points. But can someone let me know how to get the quintile points? Thanks!

Is it possible to test coefficient estimates across two samples using GMM model?

Dear All,

I run the same GMM model in two different samples (firms which have high imported input vs low imported input). I would like to test the coefficient estimates (particularly for fx) across specifications. How can I do this?
Thank you in advance.
Have a great day!
Nazlı


xtdpd expshare l1.expshare fx dllabprod VIX Dolratetota lrsale col leverage2 lFGDP_s ipsectoralgrowth log_GDP if year>2001 & dummy_highimport==1, dgmmiv(Dolratetota lrsale dllabprod , lag(3 3)) div(lFGDP_s fx VIX ipsectoralgrowth log_GDP ) hascons twostep

xtdpd expshare l1.expshare fx dllabprod VIX Dolratetota lrsale col leverage2 lFGDP_s ipsectoralgrowth log_GDP if year>2001 & dummy_highimport==0, dgmmiv(Dolratetota lrsale dllabprod , lag(3 3)) div(lFGDP_s fx VIX ipsectoralgrowth log_GDP ) hascons twostep

Analysis for two continuous variables (not normally distributed)

Dear Statlist,

I have two continuous variables, the dependent variable is not normally distributed while the independent variable is normally distributed. Apart from Spearman's correlation (I actually am not sure if this is suitable since the dependent variable is not ordinal), I'm wondering which method I can use for analyzing the relationship between this two variables? Thank you very much.

Yue

Average Partial Effects (APE) after Dynamic Probit Model ala (Wooldridge, 2005)

I am trying to calculate the average partial effects of the state dependence and some other covariates after running a dynamic probit model. I am mainly following Wooldridge (2005), Contoyannis et al (2004), Capellari and Jenkins (2009), and Skrodal et al (2013). Assuming my model to be similar to the above papers, I am running

Code:
global var varlist           /*Covariate list*/
global var_mean varlist           /*Longitudinal Mean of $var */
global var_0 varlist           /*Initial observed values of $var */

meprobit y i.year y_0 $var_mean $var_0 $var y_lag z_lag || id: , intpoints(12)
z_lag is treatment whose effect I want to extract from the state dependence y_lag. Now I want to study the average partial effects of z_lag & y_lag on the predicted values of y. Following Wooldridge (2005), Contoyannis writes;
In this case the partial effects are averaged over the population distribution of heterogeneity and computed using the population averaged parameters ... Wooldridge shows that computing the partial effect at the observed values of the regressors for each observation and averaging the estimates over the observations provides a consistent estimate of the APE
From my understanding, this what is done by the "margins, dydx()" command after the meprobit. I want to confirm that I am correct in assuming that the following code will calculate the APE of y_lage and z_lag on the outcome, as calculated by Wooldridge and Contoyannis

Code:
margins, dydx(y_lag z_lag) nose
Thanks
Soumya

Bysort

Hello,

I have reproduced a simple replica of a bigger problem.

I have data which looks as attached. I need, the value against HS 3201 as the sum of values against HS 32010, 32011, 32012, 32013 and similarly for HS 3202 to be the addition of values against 32021, 32022, 32023, 32024.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(HS Value Desired)
 3201  .  10
32010  1  10
32011  2  10
32012  3  10
32013  4  10
 3202  . 110
32021 11 110
32022 22 110
32023 33 110
32024 44 110
end

Request your help for the relevant bysort / any other command to perform this.

Thanks in advance!

Struggling with Collinearity in Panel Data

Hi,

I am struggling with how to set up my regression robustness check. I am currently running a regression of recycling rates on income, population density and several other variables.

I have panel data of 350 local authorities over 20 quarters so have used
xtset acode qdate
xtreg recycling loginc logpopden loghhsize (unitary) md11 md12 md13 md14 md15 md16 md17 md18 md19 md20 md21 md22 md23 md24 md25 md26 md27 md28 md29 md291 wasteavg dryavg quarter2 quarter3 quarter4, fe vce(robust)


Some local authorities are Unitary and some are not. I would like to test whether unitary authorities have a higher recycling rate, however whenever I include my dummy for Unitary (takes the value one if that local authority is unitary), I get collinearity. Have I missed something?
Should I run two separate regressions for if Unitary= 1 and Unitary =0 and test if they are statistically different?

Below is a sample of my data.
Thank you!

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str43 name str9 code int year byte quarter float(qdate quarter2 quarter3 quarter4 recycling loginc logpopden loghhsize) byte unitarydummy
"Hartlepool Borough Council"           "E06000001" 2012 1 208 0 0 0  31.64322 9.576926 2.2529745 .8586616 1
"Hartlepool Borough Council"           "E06000001" 2012 2 209 1 0 0  29.11372 9.576926  2.261659 .8586616 1
"Hartlepool Borough Council"           "E06000001" 2012 3 210 0 1 0 24.318804 9.576926  2.261659 .8586616 1
"Hartlepool Borough Council"           "E06000001" 2012 4 211 0 0 1  23.49204 9.576926  2.261659 .8586616 1
"Hartlepool Borough Council"           "E06000001" 2013 1 212 0 0 0  29.75906  9.58011 2.2631164 .8628899 1
"Hartlepool Borough Council"           "E06000001" 2013 2 213 1 0 0 25.608576  9.58011 2.2631164 .8628899 1
"Hartlepool Borough Council"           "E06000001" 2013 3 214 0 1 0  19.14898  9.58011 2.2631164 .8628899 1
"Hartlepool Borough Council"           "E06000001" 2013 4 215 0 0 1 26.363016  9.58011 2.2631164 .8628899 1
"Hartlepool Borough Council"           "E06000001" 2014 1 216 0 0 0  29.21854 9.606159 2.2677865 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2014 2 217 1 0 0 22.891203 9.606159 2.2631164 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2014 3 218 0 1 0 22.664324 9.606159 2.2677865 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2014 4 219 0 0 1    19.374 9.606159 2.2677865 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2015 1 220 0 0 0  25.64599 9.642772 2.2669578 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2015 2 221 1 0 0 24.093536 9.642772 2.2669578 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2015 3 222 0 1 0 23.910435 9.642772 2.2669578 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2015 4 223 0 0 1  22.74303 9.642772 2.2669578 .8671005 1
"Hartlepool Borough Council"           "E06000001" 2016 1 224 0 0 0 25.628105 9.620527  2.265921 .8712934 1
"Hartlepool Borough Council"           "E06000001" 2016 2 225 1 0 0 21.490993 9.620527  2.265921 .8712934 1
"Hartlepool Borough Council"           "E06000001" 2016 3 226 0 1 0  20.56008 9.620527  2.265921 .8712934 1
"Hartlepool Borough Council"           "E06000001" 2016 4 227 0 0 1  19.26644 9.620527  2.265921 .8712934 1
"Middlesbrough Borough Council"        "E06000002" 2012 1 208 0 0 0  15.01909 9.554639  3.262778 .8586616 1
"Middlesbrough Borough Council"        "E06000002" 2012 2 209 1 0 0 14.171424 9.554639  3.234316 .8586616 1
"Middlesbrough Borough Council"        "E06000002" 2012 3 210 0 1 0 13.453314 9.554639  3.234316 .8586616 1
"Middlesbrough Borough Council"        "E06000002" 2012 4 211 0 0 1  13.24626 9.554639  3.234316 .8586616 1
"Middlesbrough Borough Council"        "E06000002" 2013 1 212 0 0 0  14.57947 9.564863  3.236794 .8628899 1
"Middlesbrough Borough Council"        "E06000002" 2013 2 213 1 0 0 14.828068 9.564863  3.236794 .8628899 1
"Middlesbrough Borough Council"        "E06000002" 2013 3 214 0 1 0 14.709766 9.564863  3.236794 .8628899 1
"Middlesbrough Borough Council"        "E06000002" 2013 4 215 0 0 1  20.44064 9.564863  3.236794 .8628899 1
"Middlesbrough Borough Council"        "E06000002" 2014 1 216 0 0 0 34.159927 9.601301 3.2381685 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2014 2 217 1 0 0  24.25953 9.601301  3.236794 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2014 3 218 0 1 0  24.04574 9.601301 3.2381685 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2014 4 219 0 0 1    24.127 9.601301 3.2381685 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2015 1 220 0 0 0  27.94404 9.626811  3.239502 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2015 2 221 1 0 0 23.334343 9.626811  3.239502 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2015 3 222 0 1 0  19.43632 9.626811  3.239502 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2015 4 223 0 0 1  23.32905 9.626811  3.239502 .8671005 1
"Middlesbrough Borough Council"        "E06000002" 2016 1 224 0 0 0  23.50695 9.613669   3.24228 .8712934 1
"Middlesbrough Borough Council"        "E06000002" 2016 2 225 1 0 0 20.070557 9.613669   3.24228 .8712934 1
"Middlesbrough Borough Council"        "E06000002" 2016 3 226 0 1 0 19.601873 9.613669   3.24228 .8712934 1
"Middlesbrough Borough Council"        "E06000002" 2016 4 227 0 0 1  21.82984 9.613669   3.24228 .8712934 1
"Redcar and Cleveland Borough Council" "E06000003" 2012 1 208 0 0 0  23.51096 9.537339  1.728642 .8586616 1
"Redcar and Cleveland Borough Council" "E06000003" 2012 2 209 1 0 0  20.10306 9.537339  1.712536 .8586616 1
"Redcar and Cleveland Borough Council" "E06000003" 2012 3 210 0 1 0  19.72007 9.537339  1.712536 .8586616 1
"Redcar and Cleveland Borough Council" "E06000003" 2012 4 211 0 0 1 22.403687 9.537339  1.712536 .8586616 1
"Redcar and Cleveland Borough Council" "E06000003" 2013 1 212 0 0 0 24.170063 9.545955  1.710911 .8628899 1
"Redcar and Cleveland Borough Council" "E06000003" 2013 2 213 1 0 0  23.99578 9.545955  1.710911 .8628899 1
"Redcar and Cleveland Borough Council" "E06000003" 2013 3 214 0 1 0 24.617693 9.545955  1.710911 .8628899 1
"Redcar and Cleveland Borough Council" "E06000003" 2013 4 215 0 0 1  30.60893 9.545955  1.710911 .8628899 1
"Redcar and Cleveland Borough Council" "E06000003" 2014 1 216 0 0 0  36.69286 9.575816 1.7105495 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2014 2 217 1 0 0  23.24818 9.575816  1.710911 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2014 3 218 0 1 0  28.21425 9.575816 1.7105495 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2014 4 219 0 0 1    33.378 9.575816 1.7105495 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2015 1 220 0 0 0 34.828026 9.600556  1.711272 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2015 2 221 1 0 0 26.965475 9.600556  1.711272 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2015 3 222 0 1 0 18.484371 9.600556  1.711272 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2015 4 223 0 0 1   22.8024 9.600556  1.711272 .8671005 1
"Redcar and Cleveland Borough Council" "E06000003" 2016 1 224 0 0 0 25.000637 9.583902  1.713077 .8712934 1
"Redcar and Cleveland Borough Council" "E06000003" 2016 2 225 1 0 0  23.34894 9.583902  1.713077 .8712934 1
"Redcar and Cleveland Borough Council" "E06000003" 2016 3 226 0 1 0  20.75586 9.583902  1.713077 .8712934 1
"Redcar and Cleveland Borough Council" "E06000003" 2016 4 227 0 0 1 25.922733 9.583902  1.713077 .8712934 1
"Stockton-on-Tees Borough Council"     "E06000004" 2012 1 208 0 0 0  20.72435 9.607841   2.19778 .8586616 1
"Stockton-on-Tees Borough Council"     "E06000004" 2012 2 209 1 0 0  19.85636 9.607841 2.1946657 .8586616 1
"Stockton-on-Tees Borough Council"     "E06000004" 2012 3 210 0 1 0 17.278917 9.607841 2.1946657 .8586616 1
"Stockton-on-Tees Borough Council"     "E06000004" 2012 4 211 0 0 1  20.15345 9.607841 2.1946657 .8586616 1
"Stockton-on-Tees Borough Council"     "E06000004" 2013 1 212 0 0 0  22.03593 9.608176  2.197891 .8628899 1
"Stockton-on-Tees Borough Council"     "E06000004" 2013 2 213 1 0 0 18.222332 9.608176  2.197891 .8628899 1
"Stockton-on-Tees Borough Council"     "E06000004" 2013 3 214 0 1 0  17.56083 9.608176  2.197891 .8628899 1
"Stockton-on-Tees Borough Council"     "E06000004" 2013 4 215 0 0 1  19.13032 9.608176  2.197891 .8628899 1
"Stockton-on-Tees Borough Council"     "E06000004" 2014 1 216 0 0 0 21.184946 9.632138  2.201991 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2014 2 217 1 0 0 13.187984 9.632138  2.201991 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2014 3 218 0 1 0 16.005465 9.632138  2.201991 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2014 4 219 0 0 1    18.041 9.632138  2.201991 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2015 1 220 0 0 0 20.246767 9.662816  2.206735 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2015 2 221 1 0 0 16.660748 9.662816  2.206735 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2015 3 222 0 1 0  15.44666 9.662816  2.206735 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2015 4 223 0 0 1 18.055502 9.662816  2.206735 .8671005 1
"Stockton-on-Tees Borough Council"     "E06000004" 2016 1 224 0 0 0 17.611841 9.641798 2.2102504 .8712934 1
"Stockton-on-Tees Borough Council"     "E06000004" 2016 2 225 1 0 0 14.851618 9.641798 2.2102504 .8712934 1
"Stockton-on-Tees Borough Council"     "E06000004" 2016 3 226 0 1 0 14.507548 9.641798 2.2102504 .8712934 1
"Stockton-on-Tees Borough Council"     "E06000004" 2016 4 227 0 0 1  17.83563 9.641798 2.2102504 .8712934 1
"Darlington Borough Council"           "E06000005" 2012 1 208 0 0 0  42.36351 9.570878 1.6325684 .8586616 1
"Darlington Borough Council"           "E06000005" 2012 2 209 1 0 0 32.836056 9.570878  1.678964 .8586616 1
"Darlington Borough Council"           "E06000005" 2012 3 210 0 1 0  31.34309 9.570878  1.678964 .8586616 1
"Darlington Borough Council"           "E06000005" 2012 4 211 0 0 1   32.1052 9.570878  1.678964 .8586616 1
"Darlington Borough Council"           "E06000005" 2013 1 212 0 0 0 28.556936 9.597573 1.6757873 .8628899 1
"Darlington Borough Council"           "E06000005" 2013 2 213 1 0 0 30.584833 9.597573 1.6757873 .8628899 1
"Darlington Borough Council"           "E06000005" 2013 3 214 0 1 0  28.63693 9.597573 1.6757873 .8628899 1
"Darlington Borough Council"           "E06000005" 2013 4 215 0 0 1  21.55379 9.597573 1.6757873 .8628899 1
"Darlington Borough Council"           "E06000005" 2014 1 216 0 0 0  20.11268 9.606159 1.6770965 .8671005 1
"Darlington Borough Council"           "E06000005" 2014 2 217 1 0 0 26.908495 9.606159 1.6757873 .8671005 1
"Darlington Borough Council"           "E06000005" 2014 3 218 0 1 0  25.60923 9.606159 1.6770965 .8671005 1
"Darlington Borough Council"           "E06000005" 2014 4 219 0 0 1  30.62015 9.606159 1.6770965 .8671005 1
"Darlington Borough Council"           "E06000005" 2015 1 220 0 0 0 31.480186  9.65098 1.6769096 .8671005 1
"Darlington Borough Council"           "E06000005" 2015 2 221 1 0 0  29.34417  9.65098 1.6769096 .8671005 1
"Darlington Borough Council"           "E06000005" 2015 3 222 0 1 0   29.5002  9.65098 1.6769096 .8671005 1
"Darlington Borough Council"           "E06000005" 2015 4 223 0 0 1 25.388384  9.65098 1.6769096 .8671005 1
"Darlington Borough Council"           "E06000005" 2016 1 224 0 0 0  29.34344 9.647757 1.6770965 .8712934 1
"Darlington Borough Council"           "E06000005" 2016 2 225 1 0 0  27.49854 9.647757 1.6770965 .8712934 1
"Darlington Borough Council"           "E06000005" 2016 3 226 0 1 0  28.14532 9.647757 1.6770965 .8712934 1
"Darlington Borough Council"           "E06000005" 2016 4 227 0 0 1  28.00815 9.647757 1.6770965 .8712934 1
end
format %tq qdate

Problems with Nesting in Panel Regression "panels are not nested within clusters"

Hi,

I am not sure how to overcome this error message I am receiving "panels are not nested within clusters". The code I am trying to run is:

xtset acode qdate
xtreg recycling loginc logpopden loghhsize md11 md12 md13 md14 md15 md16 md17 md18 md19 md20 md21 md22 md23 md24 md25 md26 md27 md28 md29 md291 wasteavg dryavg quarter2 quarter3 quarter4, fe vce(cluster acode)


I am regressing the recycling rate on income, population density, household size, dummies for method, waste and dry average frequencies, quarter dummies.

Below is a sample of my data.

Furthermore I am having trouble even when I don't cluster and just have the below code, my quarter dummy variables are omitted for collinearity. Why is this happening?

xtreg recycling loginc logpopden loghhsize gcses alevels unitary md11 md12 md13 md14 md15 md16 md17 md18 md19 md20 md21 md22 md23 md24 md25 md26 md27 md28 md29 md291 wasteavg dryavg quarter2 quarter3 quarter4, fe vce(robust)

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str43 name str9 code int year byte quarter float(qdate quarter2 quarter3 quarter4 recycling loginc logpopden loghhsize)
"Hartlepool Borough Council"           "E06000001" 2012 1 208 0 0 0  31.64322 9.576926 2.2529745 .8586616
"Hartlepool Borough Council"           "E06000001" 2012 2 209 1 0 0  29.11372 9.576926  2.261659 .8586616
"Hartlepool Borough Council"           "E06000001" 2012 3 210 0 1 0 24.318804 9.576926  2.261659 .8586616
"Hartlepool Borough Council"           "E06000001" 2012 4 211 0 0 1  23.49204 9.576926  2.261659 .8586616
"Hartlepool Borough Council"           "E06000001" 2013 1 212 0 0 0  29.75906  9.58011 2.2631164 .8628899
"Hartlepool Borough Council"           "E06000001" 2013 2 213 1 0 0 25.608576  9.58011 2.2631164 .8628899
"Hartlepool Borough Council"           "E06000001" 2013 3 214 0 1 0  19.14898  9.58011 2.2631164 .8628899
"Hartlepool Borough Council"           "E06000001" 2013 4 215 0 0 1 26.363016  9.58011 2.2631164 .8628899
"Hartlepool Borough Council"           "E06000001" 2014 1 216 0 0 0  29.21854 9.606159 2.2677865 .8671005
"Hartlepool Borough Council"           "E06000001" 2014 2 217 1 0 0 22.891203 9.606159 2.2631164 .8671005
"Hartlepool Borough Council"           "E06000001" 2014 3 218 0 1 0 22.664324 9.606159 2.2677865 .8671005
"Hartlepool Borough Council"           "E06000001" 2014 4 219 0 0 1    19.374 9.606159 2.2677865 .8671005
"Hartlepool Borough Council"           "E06000001" 2015 1 220 0 0 0  25.64599 9.642772 2.2669578 .8671005
"Hartlepool Borough Council"           "E06000001" 2015 2 221 1 0 0 24.093536 9.642772 2.2669578 .8671005
"Hartlepool Borough Council"           "E06000001" 2015 3 222 0 1 0 23.910435 9.642772 2.2669578 .8671005
"Hartlepool Borough Council"           "E06000001" 2015 4 223 0 0 1  22.74303 9.642772 2.2669578 .8671005
"Hartlepool Borough Council"           "E06000001" 2016 1 224 0 0 0 25.628105 9.620527  2.265921 .8712934
"Hartlepool Borough Council"           "E06000001" 2016 2 225 1 0 0 21.490993 9.620527  2.265921 .8712934
"Hartlepool Borough Council"           "E06000001" 2016 3 226 0 1 0  20.56008 9.620527  2.265921 .8712934
"Hartlepool Borough Council"           "E06000001" 2016 4 227 0 0 1  19.26644 9.620527  2.265921 .8712934
"Middlesbrough Borough Council"        "E06000002" 2012 1 208 0 0 0  15.01909 9.554639  3.262778 .8586616
"Middlesbrough Borough Council"        "E06000002" 2012 2 209 1 0 0 14.171424 9.554639  3.234316 .8586616
"Middlesbrough Borough Council"        "E06000002" 2012 3 210 0 1 0 13.453314 9.554639  3.234316 .8586616
"Middlesbrough Borough Council"        "E06000002" 2012 4 211 0 0 1  13.24626 9.554639  3.234316 .8586616
"Middlesbrough Borough Council"        "E06000002" 2013 1 212 0 0 0  14.57947 9.564863  3.236794 .8628899
"Middlesbrough Borough Council"        "E06000002" 2013 2 213 1 0 0 14.828068 9.564863  3.236794 .8628899
"Middlesbrough Borough Council"        "E06000002" 2013 3 214 0 1 0 14.709766 9.564863  3.236794 .8628899
"Middlesbrough Borough Council"        "E06000002" 2013 4 215 0 0 1  20.44064 9.564863  3.236794 .8628899
"Middlesbrough Borough Council"        "E06000002" 2014 1 216 0 0 0 34.159927 9.601301 3.2381685 .8671005
"Middlesbrough Borough Council"        "E06000002" 2014 2 217 1 0 0  24.25953 9.601301  3.236794 .8671005
"Middlesbrough Borough Council"        "E06000002" 2014 3 218 0 1 0  24.04574 9.601301 3.2381685 .8671005
"Middlesbrough Borough Council"        "E06000002" 2014 4 219 0 0 1    24.127 9.601301 3.2381685 .8671005
"Middlesbrough Borough Council"        "E06000002" 2015 1 220 0 0 0  27.94404 9.626811  3.239502 .8671005
"Middlesbrough Borough Council"        "E06000002" 2015 2 221 1 0 0 23.334343 9.626811  3.239502 .8671005
"Middlesbrough Borough Council"        "E06000002" 2015 3 222 0 1 0  19.43632 9.626811  3.239502 .8671005
"Middlesbrough Borough Council"        "E06000002" 2015 4 223 0 0 1  23.32905 9.626811  3.239502 .8671005
"Middlesbrough Borough Council"        "E06000002" 2016 1 224 0 0 0  23.50695 9.613669   3.24228 .8712934
"Middlesbrough Borough Council"        "E06000002" 2016 2 225 1 0 0 20.070557 9.613669   3.24228 .8712934
"Middlesbrough Borough Council"        "E06000002" 2016 3 226 0 1 0 19.601873 9.613669   3.24228 .8712934
"Middlesbrough Borough Council"        "E06000002" 2016 4 227 0 0 1  21.82984 9.613669   3.24228 .8712934
"Redcar and Cleveland Borough Council" "E06000003" 2012 1 208 0 0 0  23.51096 9.537339  1.728642 .8586616
"Redcar and Cleveland Borough Council" "E06000003" 2012 2 209 1 0 0  20.10306 9.537339  1.712536 .8586616
"Redcar and Cleveland Borough Council" "E06000003" 2012 3 210 0 1 0  19.72007 9.537339  1.712536 .8586616
"Redcar and Cleveland Borough Council" "E06000003" 2012 4 211 0 0 1 22.403687 9.537339  1.712536 .8586616
"Redcar and Cleveland Borough Council" "E06000003" 2013 1 212 0 0 0 24.170063 9.545955  1.710911 .8628899
"Redcar and Cleveland Borough Council" "E06000003" 2013 2 213 1 0 0  23.99578 9.545955  1.710911 .8628899
"Redcar and Cleveland Borough Council" "E06000003" 2013 3 214 0 1 0 24.617693 9.545955  1.710911 .8628899
"Redcar and Cleveland Borough Council" "E06000003" 2013 4 215 0 0 1  30.60893 9.545955  1.710911 .8628899
"Redcar and Cleveland Borough Council" "E06000003" 2014 1 216 0 0 0  36.69286 9.575816 1.7105495 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2014 2 217 1 0 0  23.24818 9.575816  1.710911 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2014 3 218 0 1 0  28.21425 9.575816 1.7105495 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2014 4 219 0 0 1    33.378 9.575816 1.7105495 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2015 1 220 0 0 0 34.828026 9.600556  1.711272 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2015 2 221 1 0 0 26.965475 9.600556  1.711272 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2015 3 222 0 1 0 18.484371 9.600556  1.711272 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2015 4 223 0 0 1   22.8024 9.600556  1.711272 .8671005
"Redcar and Cleveland Borough Council" "E06000003" 2016 1 224 0 0 0 25.000637 9.583902  1.713077 .8712934
"Redcar and Cleveland Borough Council" "E06000003" 2016 2 225 1 0 0  23.34894 9.583902  1.713077 .8712934
"Redcar and Cleveland Borough Council" "E06000003" 2016 3 226 0 1 0  20.75586 9.583902  1.713077 .8712934
"Redcar and Cleveland Borough Council" "E06000003" 2016 4 227 0 0 1 25.922733 9.583902  1.713077 .8712934
"Stockton-on-Tees Borough Council"     "E06000004" 2012 1 208 0 0 0  20.72435 9.607841   2.19778 .8586616
"Stockton-on-Tees Borough Council"     "E06000004" 2012 2 209 1 0 0  19.85636 9.607841 2.1946657 .8586616
"Stockton-on-Tees Borough Council"     "E06000004" 2012 3 210 0 1 0 17.278917 9.607841 2.1946657 .8586616
"Stockton-on-Tees Borough Council"     "E06000004" 2012 4 211 0 0 1  20.15345 9.607841 2.1946657 .8586616
"Stockton-on-Tees Borough Council"     "E06000004" 2013 1 212 0 0 0  22.03593 9.608176  2.197891 .8628899
"Stockton-on-Tees Borough Council"     "E06000004" 2013 2 213 1 0 0 18.222332 9.608176  2.197891 .8628899
"Stockton-on-Tees Borough Council"     "E06000004" 2013 3 214 0 1 0  17.56083 9.608176  2.197891 .8628899
"Stockton-on-Tees Borough Council"     "E06000004" 2013 4 215 0 0 1  19.13032 9.608176  2.197891 .8628899
"Stockton-on-Tees Borough Council"     "E06000004" 2014 1 216 0 0 0 21.184946 9.632138  2.201991 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2014 2 217 1 0 0 13.187984 9.632138  2.201991 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2014 3 218 0 1 0 16.005465 9.632138  2.201991 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2014 4 219 0 0 1    18.041 9.632138  2.201991 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2015 1 220 0 0 0 20.246767 9.662816  2.206735 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2015 2 221 1 0 0 16.660748 9.662816  2.206735 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2015 3 222 0 1 0  15.44666 9.662816  2.206735 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2015 4 223 0 0 1 18.055502 9.662816  2.206735 .8671005
"Stockton-on-Tees Borough Council"     "E06000004" 2016 1 224 0 0 0 17.611841 9.641798 2.2102504 .8712934
"Stockton-on-Tees Borough Council"     "E06000004" 2016 2 225 1 0 0 14.851618 9.641798 2.2102504 .8712934
"Stockton-on-Tees Borough Council"     "E06000004" 2016 3 226 0 1 0 14.507548 9.641798 2.2102504 .8712934
"Stockton-on-Tees Borough Council"     "E06000004" 2016 4 227 0 0 1  17.83563 9.641798 2.2102504 .8712934
"Darlington Borough Council"           "E06000005" 2012 1 208 0 0 0  42.36351 9.570878 1.6325684 .8586616
"Darlington Borough Council"           "E06000005" 2012 2 209 1 0 0 32.836056 9.570878  1.678964 .8586616
"Darlington Borough Council"           "E06000005" 2012 3 210 0 1 0  31.34309 9.570878  1.678964 .8586616
"Darlington Borough Council"           "E06000005" 2012 4 211 0 0 1   32.1052 9.570878  1.678964 .8586616
"Darlington Borough Council"           "E06000005" 2013 1 212 0 0 0 28.556936 9.597573 1.6757873 .8628899
"Darlington Borough Council"           "E06000005" 2013 2 213 1 0 0 30.584833 9.597573 1.6757873 .8628899
"Darlington Borough Council"           "E06000005" 2013 3 214 0 1 0  28.63693 9.597573 1.6757873 .8628899
"Darlington Borough Council"           "E06000005" 2013 4 215 0 0 1  21.55379 9.597573 1.6757873 .8628899
"Darlington Borough Council"           "E06000005" 2014 1 216 0 0 0  20.11268 9.606159 1.6770965 .8671005
"Darlington Borough Council"           "E06000005" 2014 2 217 1 0 0 26.908495 9.606159 1.6757873 .8671005
"Darlington Borough Council"           "E06000005" 2014 3 218 0 1 0  25.60923 9.606159 1.6770965 .8671005
"Darlington Borough Council"           "E06000005" 2014 4 219 0 0 1  30.62015 9.606159 1.6770965 .8671005
"Darlington Borough Council"           "E06000005" 2015 1 220 0 0 0 31.480186  9.65098 1.6769096 .8671005
"Darlington Borough Council"           "E06000005" 2015 2 221 1 0 0  29.34417  9.65098 1.6769096 .8671005
"Darlington Borough Council"           "E06000005" 2015 3 222 0 1 0   29.5002  9.65098 1.6769096 .8671005
"Darlington Borough Council"           "E06000005" 2015 4 223 0 0 1 25.388384  9.65098 1.6769096 .8671005
"Darlington Borough Council"           "E06000005" 2016 1 224 0 0 0  29.34344 9.647757 1.6770965 .8712934
"Darlington Borough Council"           "E06000005" 2016 2 225 1 0 0  27.49854 9.647757 1.6770965 .8712934
"Darlington Borough Council"           "E06000005" 2016 3 226 0 1 0  28.14532 9.647757 1.6770965 .8712934
"Darlington Borough Council"           "E06000005" 2016 4 227 0 0 1  28.00815 9.647757 1.6770965 .8712934
end
format %tq qdate

problema with local extended_fcn local list : dir . files "*"

Hello everyone.

this is my first post in Statalist, so please forgive any mistake on it.

I'm trying to capture the filenames of several files in any given directory using:

local filename : dir . files "*"

This actually works and it creates a local named `filename' containing the names of every file in the directory. The problem is that it does not separates the filenames from eachother, so I get a string: fosis.xlsxjunaeb.xlsxmatriz2019.xlsxmineduc.xlsxse nama.xlsxsename.xlsxsence.xlsxsernameg.xlsxssmds.x lsxsstrabajo.xlsx (names are arbitrary)

Thus, I am unable to work with each file separatedly as I would like. Does anyone knows how to solve this?

I appreciate your answers.

Replace missing observations in VAR1 with observations from VAR2 f

Dear forum,

I am trying to replace the missing observation(s) in ExportMarkets with the value in MirrorExportMarkets. May I ask what the command is for this?

ExportMarkets MirrorExportMarkets
1991 . 45 67
1992 . . 58
1993 . 97 89

Kind regards,
Ray

Exporting underlying data behind stata generated graphs

Hi, i was able to export the underlying data behind a graph i created using a dataset (below)
but when i do, i only get the mediam values and not the ci (confidence intervals). How can i modify the code so that the exported excel dataset also includes values for CIs?

sts graph, failure ci
serset use
export excel "hazard.xlsx",sheetreplace
serset clear



How to compare prognostic models with a survivaldecision curve analysis for survival outcomes?

Hello,
i am currently using the dca (stdca) command in stata 14.0
I research a dataset of patients with a prognostic marker and would like to compare the recurrence free survival at one year, 3 years and 5 years of the standard model with a "full" model that includes the marker (so one more covariate basically).
I know how to compare the two models for recurrence in general and i know how to do a dca for survival outcomes. But i can not figure out how to create the graph to compare the two models for survival outcomes at different follow-up points. I am familiar with the pdf of Vickert et al. https://www.mskcc.org/sites/default/...-2015-2-26.pdf , but i feel like it does not cover what i attempt. Does anyone have an idea on how to do it? i know that it is possible in R as well, but i have very (and i mean VERY) limited knowledge in R. Is it even possible in stata?
I hope somebody can help me and that its not too dumb a question.

Cheers,

Florian

Subpop MLM: Xtmixed


Hi all,
I am running a multi-level modeling using complex survey data, which used a stratified, clustered, and unequally sampling design. For my research questions, I have to select a subsample, but due to the weight issues, I think I am not able to create a new tiny dataset which only includes my subsample. For regular regression analyses, I use SVY, subpop (): regress command, but I wonder if it would be possible to use a similar command for MLM with a subpop and continuous outcomes in Stata. If not possible, any thoughts on another approach to deal with it?

Thank you so much!


Sample selection in the control function approach

I am trying to understand what sample it is correct to use when estimating the models using the control function (CF) approach. Below, I explain what I mean.

The CF approach is an alternative to xtivreg, fe estimation. Suppose X is an endogenous independent variable. In the CF approach, we first run
xtreg X Z C1 C2, fe, where
C1 and C2 are controls from the first stage and Z is an instrument); then predict residuals with
predict CF, resid
and then insert CF in the first stage:
xtreg Y X C1 C2 CF, fe
In this case, coefficients for X, C1, and C2 should be the same in both xtreg Y X C1 C2 CF, fe and xtivreg Y C1 C2 (X = Z), fe, while standard errors will differ if we do not adjust the ones from xtreg, fe via bootsrapping (I did not use bootstrapping in order not to create additional confusion).

Indeed, here are the results of xtreg, fe and xtivreg, fe I derived using the nlswork data:

xtreg, fe (errors not bootstrapped)
Code:
webuse nlswork, clear
quietly xtreg tenure union south age c.age#c.age not_smsa, fe
predict cf, resid
xtreg ln_w tenure age c.age#c.age not_smsa cf, fe

Fixed-effects (within) regression               Number of obs     =     19,007
Group variable: idcode                          Number of groups  =      4,134

R-sq:                                           Obs per group:
     within  = 0.1328                                         min =          1
     between = 0.2365                                         avg =        4.6
     overall = 0.2073                                         max =         12

                                                F(5,14868)        =     455.53
corr(u_i, Xb)  = 0.2033                         Prob > F          =     0.0000

------------------------------------------------------------------------------
     ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      tenure |   .2403531   .0151385    15.88   0.000     .2106797    .2700264
         age |   .0118437   .0036499     3.24   0.001     .0046894     .018998
             |
 c.age#c.age |  -.0012145   .0000798   -15.22   0.000    -.0013709    -.001058
             |
    not_smsa |  -.0167178   .0137527    -1.22   0.224    -.0436748    .0102393
          cf |  -.2227325   .0151602   -14.69   0.000    -.2524484   -.1930167
       _cons |   1.678287   .0659452    25.45   0.000     1.549027    1.807548
-------------+----------------------------------------------------------------
     sigma_u |  .38999138
     sigma_e |  .25552281
         rho |  .69964877   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(4133, 14868) = 8.30                 Prob > F = 0.0000
xtivreg, fe:
Code:
xtivreg ln_w age c.age#c.age not_smsa (tenure = union south), fe

Fixed-effects (within) IV regression            Number of obs     =     19,007
Group variable: idcode                          Number of groups  =      4,134

R-sq:                                           Obs per group:
     within  =      .                                         min =          1
     between = 0.1304                                         avg =        4.6
     overall = 0.0897                                         max =         12

                                                Wald chi2(4)      =  147926.58
corr(u_i, Xb)  = -0.6843                        Prob > chi2       =     0.0000

------------------------------------------------------------------------------
     ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      tenure |   .2403531   .0373419     6.44   0.000     .1671643    .3135419
         age |   .0118437   .0090032     1.32   0.188    -.0058023    .0294897
             |
 c.age#c.age |  -.0012145   .0001968    -6.17   0.000    -.0016003   -.0008286
             |
    not_smsa |  -.0167178   .0339236    -0.49   0.622    -.0832069    .0497713
       _cons |   1.678287   .1626657    10.32   0.000     1.359468    1.997106
-------------+----------------------------------------------------------------
     sigma_u |  .70661941
     sigma_e |  .63029359
         rho |  .55690561   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F  test that all u_i=0:     F(4133,14869) =     1.44      Prob > F    = 0.0000
------------------------------------------------------------------------------
Instrumented:   tenure
Instruments:    age c.age#c.age not_smsa union south
------------------------------------------------------------------------------
As you could see, coefficients are the same, just standard errors differ (standard errors equalize once bootstrapped that confirms that both approaches yield the exact same results when the same instrument is used).

However, my question is about which sample in the first stage it is correct to use once our explanatory variables are lagged?

Fixed-effects IV estimator:
Code:
xtivreg ln_w l.age cl.age#cl.age l.not_smsa (l.tenure = l.union l.south), fe

Fixed-effects (within) IV regression            Number of obs     =      7,500
Group variable: idcode                          Number of groups  =      3,294

R-sq:                                           Obs per group:
     within  =      .                                         min =          1
     between = 0.0685                                         avg =        2.3
     overall = 0.0571                                         max =          6

                                                Wald chi2(4)      =   80781.56
corr(u_i, Xb)  = -0.5474                        Prob > chi2       =     0.0000

------------------------------------------------------------------------------
     ln_wage |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      tenure |
         L1. |   .1755435   .0389611     4.51   0.000     .0991811    .2519059
             |
         age |
         L1. |   .0106753   .0134104     0.80   0.426    -.0156085    .0369592
             |
      cL.age#|
      cL.age |  -.0008867   .0002305    -3.85   0.000    -.0013384   -.0004351
             |
    not_smsa |
         L1. |  -.0452809   .0509685    -0.89   0.374    -.1451773    .0546154
             |
       _cons |   1.671945   .2302329     7.26   0.000     1.220697    2.123194
-------------+----------------------------------------------------------------
     sigma_u |  .59050356
     sigma_e |  .54146412
         rho |  .54324114   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F  test that all u_i=0:     F(3293,4202) =     1.08       Prob > F    = 0.0089
------------------------------------------------------------------------------
Instrumented:   L.tenure
Instruments:    L.age cL.age#cL.age L.not_smsa L.union L.south
------------------------------------------------------------------------------
Gives the same results as the following CF model:
Code:
quietly xtreg l.tenure l.union l.south l.age cl.age#cl.age l.not_smsa, fe
predict cf, resid
xtreg ln_w l.tenure l.age cl.age#cl.age l.not_smsa cf, fe

Fixed-effects (within) regression               Number of obs     =      7,500
Group variable: idcode                          Number of groups  =      3,294

R-sq:                                           Obs per group:
     within  = 0.1351                                         min =          1
     between = 0.1783                                         avg =        2.3
     overall = 0.1770                                         max =          6

                                                F(5,4201)         =     131.21
corr(u_i, Xb)  = 0.1436                         Prob > F          =     0.0000

------------------------------------------------------------------------------
     ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      tenure |
         L1. |   .1755435   .0205221     8.55   0.000     .1353094    .2157776
             |
         age |
         L1. |   .0106753   .0070637     1.51   0.131    -.0031732    .0245239
             |
      cL.age#|
      cL.age |  -.0008867   .0001214    -7.30   0.000    -.0011247   -.0006488
             |
    not_smsa |
         L1. |  -.0452809   .0268467    -1.69   0.092    -.0979147    .0073528
             |
          cf |  -.1641325    .020582    -7.97   0.000     -.204484   -.1237809
       _cons |   1.671945   .1212711    13.79   0.000      1.43419    1.909701
-------------+----------------------------------------------------------------
     sigma_u |  .41441731
     sigma_e |   .2852065
         rho |  .67859444   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(3293, 4201) = 3.72                  Prob > F = 0.0000
However, if do not use lags in the first stage and lag the residual in the second stage instead, the coefficients differ.

Code:
quietly xtreg tenure union south age c.age#c.age not_smsa, fe
predict cf, resid
xtreg ln_w l.tenure l.age cl.age#cl.age l.not_smsa l.cf, fe

Fixed-effects (within) regression               Number of obs     =      7,500
Group variable: idcode                          Number of groups  =      3,294

R-sq:                                           Obs per group:
     within  = 0.1353                                         min =          1
     between = 0.1785                                         avg =        2.3
     overall = 0.1767                                         max =          6

                                                F(5,4201)         =     131.45
corr(u_i, Xb)  = 0.1454                         Prob > F          =     0.0000

------------------------------------------------------------------------------
     ln_wage |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      tenure |
         L1. |   .2566965   .0304213     8.44   0.000     .1970547    .3163383
             |
         age |
         L1. |   .0144529    .006859     2.11   0.035     .0010056    .0279002
             |
      cL.age#|
      cL.age |  -.0013382   .0001577    -8.48   0.000    -.0016475    -.001029
             |
    not_smsa |
         L1. |  -.0346281    .027326    -1.27   0.205    -.0882015    .0189453
             |
          cf |
         L1. |  -.2452925   .0305005    -8.04   0.000    -.3050896   -.1854954
             |
       _cons |   1.710315   .1238945    13.80   0.000     1.467417    1.953214
-------------+----------------------------------------------------------------
     sigma_u |  .41454272
     sigma_e |  .28517027
         rho |  .67878182   (fraction of variance due to u_i)
------------------------------------------------------------------------------
F test that all u_i=0: F(3293, 4201) = 3.72                  Prob > F = 0.0000
Is it completely incorrect to do this
Code:
quietly xtreg tenure union south age c.age#c.age not_smsa, fe
predict cf, resid
xtreg ln_w l.tenure l.age cl.age#cl.age l.not_smsa l.cf, fe
instead of this?
Code:
quietly xtreg l.tenure l.union l.south l.age cl.age#cl.age l.not_smsa, fe
predict cf, resid
xtreg ln_w l.tenure l.age cl.age#cl.age l.not_smsa cf, fe
Sorry for a long post. I just wanted to demonstrate my reasoning with examples.




Can't open miest.ster

Dear Statalist,

I am trying do run a Cox regression on an imputed dataset using restricted cubic splines. I used the following code (the data are correctly stset, and stcox using the imputed datasets works fine):

Code:
mi set mlong                                                                                                                                     
mi register imputed HADSA_gli PartAg_gli Sex                                                                                                                  
mi impute chained (pmm, knn(10)) HADSA_gli PartAg_gli Sex , add(10)  

mi estimate, post  sav(miest, replace) : stcox i.HADS_A_gli PartAggli_spline1 PartAggli_spline2 i.Sex if glicopd_HUNT==1 | glicopd_HUNT==2 & HADS_A_gli!=. & PartAg_gli>=40.0 & PartAg_gli<=85.0
When I run the last command, I get the error message
r(603); file miest.ster could not be opened
, meaning that miest.ster exists, but can't be opened.

What do I do wrong?


lower what does mean?

hi friends. please help me to understand this code. what does mean lower?
gen cityname2=lower(cityofprop)+", "+ lower(stateofprop)

Adding missing values in a varlist

Hi,

In my data set answers below zero each show a different type of missing value (e.g. not answered or not asked etc. from -1 to -10) and I want to replace them all with missing values.

I have made a global list named alist like this:

global alist Date Age Education Employment1 Employment2 Sex Stress1 Stress2 ///
JobControl1 JobControl2 JobControl3 JobDemand1 JobDemand2 JobDemand3 ///
Depression1 Depression2 Depression3 Depression4 Depression5 SocialSupport1 ///
SocialSupport2 SocialSupport3 SocialSupport4 SocialSupport5 SocialSupport6 ///
SocialSupport7 SocialSupport8 SocialSupport9 SocialSupport10
and then called them to be replaced like this:

foreach var of $alist {replace `var' =. if (`var'<=0)}
but I am getting this error that tell me :
program error: code follows on the same line as open brace
can any one tell me what should I change? I've been googling but could not find any way to do it.

Many thanks and appreciation.


Endogenous binary regressor in multinomial logit model

Hello forum members,

i do have a multinomial logit model where one binary explanatory variable is endogenous (EEV). I am aware of solutions for the case of binary outcome variable and binary EEV, such as, e.g. bivariay probit models (see Wooldrige, 2010, p. 595 ff.) - which is conveniently implemented in Stata's biprobit function.

However, are you aware of any approach for the case of categorical outcomes (e.g. multinomial logit) and binary EEV? [Any help is appreciated]

Refs.
Wooldridge, J. M. (2010). Econometric Analysis of Cross Section and Panel Data. MIT press.

Help with event study on the impact of Hurricane Harvey on the US stock market using SP500 company data

Dear Reader,

I would like some help with a study I am doing at University. I have downloaded data regarding stock prices for companies located in the states affected by Hurricane Harvey and would like to run an event study to find out returns, expected returns, abnormal returns, cumulative abnormal returns, T test, AAR, CAAR and the hypothesis whether abnormal returns are statistically different from zero. However I have not been taught how to do these calculations on Stata therefore any help would be much appreciated. Regards,

Amrit Thind.

Bootstrap after two stage probit

Dear all,
I was using ivprobit but it seems there is a problem with the margins command when I want to get average marginal effects. It gives the same value as the coefficient from ivprobit. Also, it takes hours to calculate the AME.
Therefore, I decided to do it manually. In the first stage, I run a linear regression for my instrument, then calculate predict.
In the second stage, I run probit with the predicted values.
I have two questions:
1-) Is this procedure exactly the same with ivprobit command?
2-) I know I need to bootstrap the standard errors for the margins command. But I don't know how to do that. I also have to use sample weights. Please let me know the correct syntax for this.

Could you please advise on me this matter?

Hypothesis Testing on coefficients

Hi

I am interested in testing the hypothesis highlighted in the picture. Ho: gamma>=beta and Ha: gamma<beta

Is there a way in stata to do this? The test command-- test beta=gamma (after running the regression) only checks for the equality and not the inequality! I am interested in the latter!


Thanks
Dhruv

Identifying units of analysis in STATA

Hi, I'm starting a master thesis and am very new to STATA with very little experience. I am looking at innovation in various technologies over time with regional data.

I have a data-set of regions (i) and their technologies (c) over 5 time periods (t). As a result, each region (i) has a number of technologies (c) and also data on each-year. How can I start using panel-data on STATA by telling to take into account this structure?

Thanks!

log using

hi friends. i am run this code but faced with error.although it is run without error yesterday, i am confused please help me
code:
log using "C:\Users\A1duneh\Desktop\CollateralChannel\ou tput/reg.log",replace
error:
file C:\Users\A1duneh\Desktop\CollateralChannel\output/reg.log cannot be modified or erased; likely cause is read-only directory or file
r(608);

Plotting categorical variables

Hi all,

can any of you tel me how I can get ht below graph?

My rep variable is life satisfaction and the independent include - marital status, age, employment status, year dummies, log income, log education.

I want to make three graphs consequently for married, singles and the ones that change their marital status from single to married. For the last one I assume an RD plot will be needed. But in general, how can I plot life satisfaction which is categorical variable to show exactly the categories (as whoso on the photo). I have limited the sample to married and single and the age I need.

Thanks you!

Regards,
Gabriela