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

xtheckman warning

$
0
0
Hi, my first post to Statalist here.

I am using the newest Stata16 "xtheckman" procedure and I received the following warning:

"1544 observations incorrectly specified as noncensored in select()"

After running:

​​​​. xtheckman Y wf X_* Xdum_* mak_* fedum_* if year== 1, select(wfd = X_* Xdum_* mak_* fedum_*) noci showstep difficult

¿What does the warning imply? The number in the message (1544) changes when I change the number of covariates I include as controls in the selection equation. I am pretty sure that the dependent selection variable (wfd) is well created. My model is based on an unbalanced longitudinal (panel) data with quarterly observations of ~ 150 thousands units, I am restricting the model to the first year of the sample (year == 1).

Also, the model has been estimating for as long as 3 days so far... and it is still only in the 10 iteration. I anticipated this problem so I used the "difficult" option to switch between estimation methods. ¿Some additional advice on how to improve estimation?





comparing all observations with the observations fulfilling a certain criteria

$
0
0
Hi Statalists !
I’m new to Stata. Although my problem seems simple, I couldn’t find any solution with Stata on the internet. So I really hope somebody can help me =) Thanks a lot for helpful answers.

I want to generate a new variable which compares every observation with the observations, fulfilling a certain condition (e.g. Var1 = C).
The comparison of the observations A and B with the observations of C should only take place if they have the same value in 2 other variables (e.g. Var2 and Var3).
If the observation (A or B) is equal (in Var2 and Var3), then the new created variable should indicate if its value in Var4 are equal to the value of C in Var4.

Observation - Var1 Var2 Var3 Var4 – newVar (explanation)
1 - A 1 2 1 - 0 (compared to 6)
2 - A 2 3 1 - 1 (compared to 7)
3 - A 5 2 0 - - (no comparison)
4 - B 1 2 0 - 1 (compared to 6)
5 - B 2 3 1 - 1 (compared to 7)
6 - B 3 1 0 - - (no comparison)
6 - C 1 2 0 - 1 (compared to 6)
7 - C 2 3 1 - 1 (compared to 7)
8 - C 7 1 1 - 1 (compared to 8)

Really hope that the illustration of the problem is understandable.
Thank you ! =)

How to display "Percent of cases" in graph using mrgraph command in mrtab module

$
0
0
C2.png I am using the mrtab module from ssc to display multiple response answers using the mrgraph command.

When I use mrgraph it only displays the responses to the multi code answers as a frequency, however I would like it to be displayed as percent of cases.

The mrtab command gives the relevant data as percentage. e.g.

Code:
 mrtab C2_1 C2_2 C2_3 C2_4 C2_5 C2_6, r(1 2 3 4 5 6)
produces Array



Whereas

Code:
mrgraph hbar C2_1 C2_2 C2_3 C2_4 C2_5 C2_6, r(1 2 3 4 5 6) blabel(bar) bar(1, color("23 55 94")) graphregion(color(white)) title("Which of the following can you" "access elsewhere in your community?") sort(1) descending oversubopts(label(labsize(2.5)))
only shows the frequency:



If anyone knows the relevant code to include percent of cases in the graph rather than frequency, that would be hugely appreciated.

gcollapse merge, dont replace but change target variable

$
0
0
I have an id and variables identifying date and the id's peers. I also have a treatment variable. I would like to create a new variable using gcollapse that would show if a peer has received treatment. I have a solution that loops over days instead of gcollapse but I am frustrated because of the computational intensity.

The new variable would take the id of the first neighbor then tag all observations where the first neighbor was treated on a given day.

I've tried using the merge and replace options in gcollapse but this appears to simply replace neighbor 1 with the id column:

Code:
gcollapse treated_1 = treated neighbor = id, by(id date) merge replace
Here is a sample data set

Code:
ssc install dataex
input long id str10 date long neighbor1 long neighbor2 long treated
1 "01/01/1960" 2 4  0 
1 "01/02/1960" 2 4  0 
1 "01/03/1960" 2 4  1 
2 "01/01/1960"  1 3 0 
2 "01/02/1960"  1 3 0 
2 "01/03/1960"  1 3 0 
3 "01/01/1960"  2 4 1 
3 "01/02/1960"  2 4 0 
3 "01/03/1960"  2 4 0 
4 "01/01/1960"  3 1 0 
4 "01/02/1960"  3 1 0 
4 "01/03/1960"  3 1 0 
end


the desired outcome would look like:

Code:
input long id str10 date long neighbor1 long neighbor2 long treated long neighbor1_treated
1 "01/01/1960" 2 4  0 0
1 "01/02/1960" 2 4  0 0
1 "01/03/1960" 2 4  1 0
2 "01/01/1960"  1 3 0 0
2 "01/02/1960"  1 3 0 0
2 "01/03/1960"  1 3 0 1
3 "01/01/1960"  2 4 1 0
3 "01/02/1960"  2 4 0 0
3 "01/03/1960"  2 4 0 0
4 "01/01/1960"  3 1 0 0
4 "01/02/1960"  3 1 0 0
4 "01/03/1960"  3 1 0 0
end

spatial auto regression

$
0
0
Hi statlist users,

I have cross sectional data survey data from actors who attend many different forums; hence, if actor 1 attends three forums (Forum X, Y and Z), then actor 1 has three rows in the dataset. I am looking at how an actors perceptions spillover across the forums they attend. So my W (spatial lag) is an actor by actor matrix with the cells populated by the number of forums the actors co-participate in. I have gotten that far, however, when I try to spset my outcome data, I receive an error "variable _ID does not uniquely identify the observations". This makes sense because Actor 1 has three rows in the dataset, meaning Stata does not read 1 as uniqe because it is showing up three times.

I am unsure how to proceed because my spset id variable for the W matrix and my actual data have to align.

Any help would be greatly appreciated.

Here is an example of my data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double popid float forumid double(conflforum contribforum efficforum fairforum)
 1 452 1  7  7  9
 1 455 1  8  8  9
 1 431 1  8  8  8
 1  33 1  8  7  9
 3  85 2  9 10 10
 8  36 1  8  8  8
 8 247 1  8  8  8
 8 455 1  8  8  8
18 452 1  9  5  9
23 443 1  9  9 10
23 312 1 10  9 10
23  35 1  7  9  9
23   4 1  9  9 10
23 455 2 10  9  9
26  53 2  8  7  6
end
label values conflforum Q18e
label def Q18e 1 "For most decisions in this venue, most groups can gain as long as they can devel", modify
label def Q18e 2 "Although most groups can gain from most decisions, there is conflict over who wi", modify
label values contribforum Q19e
label def Q19e 10 "Very significant contribution", modify
label values efficforum Q20e
label def Q20e 10 "Very effective", modify
label values fairforum Q21e
label def Q21e 10 "Very fair", modify

Interpretting margins

$
0
0
Dear All,

I will be grateful for help with interpreting margins output following xtnbreg. I have a count dependent variable and two binary independent variables (post and treat). I want to estimate the impact of treatment (treat==1) after it comes into effect (post==1) on the dependent variable.

Here is what I estimate:

Code:
. eststo raw11: xtnbreg sumnalaxone  i.post##i.treat age, fe  exposure(exposure) /*vce(cl
> uster studypersonid)*/  /* WORKS*/
note: 1346 groups (2692 obs) dropped because of all zero outcomes

Iteration 0:   log likelihood = -93.131882 
Iteration 1:   log likelihood = -86.687569  (not concave)
Iteration 2:   log likelihood =  -79.12231 
Iteration 3:   log likelihood = -78.471463 
Iteration 4:   log likelihood = -78.454974 
Iteration 5:   log likelihood = -78.454966 

Conditional FE negative binomial regression     Number of obs     =        232
Group variable: studypersonid                   Number of groups  =        116

                                                Obs per group:
                                                              min =          2
                                                              avg =        2.0
                                                              max =          2

                                                Wald chi2(4)      =      80.11
Log likelihood  = -78.454966                    Prob > chi2       =     0.0000

------------------------------------------------------------------------------
 sumnalaxone |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      1.post |   1.116119   .3151385     3.54   0.000     .4984593    1.733779
     1.treat |   .1157644   .9709931     0.12   0.905    -1.787347    2.018876
             |
  post#treat |
        1 1  |   2.339803   .5109139     4.58   0.000      1.33843    3.341176
             |
         age |  -.0198788   .0452903    -0.44   0.661     -.108646    .0688885
       _cons |  -9.973896   1.557685    -6.40   0.000     -13.0269   -6.920888
ln(exposure) |          1  (exposure)
------------------------------------------------------------------------------

. margins treat, dydx(post)

Average marginal effects                        Number of obs     =        232
Model VCE    : OIM

Expression   : Linear prediction, predict()
dy/dx w.r.t. : 1.post

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
1.post       |
       treat |
          0  |   1.116119   .3151385     3.54   0.000     .4984593    1.733779
          1  |   3.455922   .4353058     7.94   0.000     2.602739    4.309106
------------------------------------------------------------------------------
Note: dy/dx for factor levels is the discrete change from the base level.

. margins treat, at (post=1)

Predictive margins                              Number of obs     =        232
Model VCE    : OIM

Expression   : Linear prediction, predict()
at           : post            =           1

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |
          0  |   -1.99617   .5378508    -3.71   0.000    -3.050338   -.9420019
          1  |   .4593975   .9043628     0.51   0.611    -1.313121    2.231916
------------------------------------------------------------------------------
I am not sure which margins command I should be using and how to interpret the outcome. I will be very grateful for any help.
Sincerely,
Sumedha.

Change in C-statistic (with confidence intervals) on imputed survival data

$
0
0
Hi everyone,

I am trying to calculate C-statistics (and change in C-statistics) with associated confidence intervals for my Cox regression model.

I have done so using the somersd package, developed by Roger Newson, for the complete case analysis. (Details here https://journals.sagepub.com/doi/pdf...867X1001000303)

After running the Cox model (stcox var1 var2 var3 etc), I used the "predict" command to calculate a hazard ratio,and then derived an inverse hazard ratio, which we expect to be a positive predictor (as suggested in the instructions in the link).

. stcox var1 var2 var3
. predict hr
. generate invhr=1/hr

I am trying to do the same for my full dataset with multiple imputation. After running Cox regession on the full imputed dataset (mi estimate, saving(mi_est) hr: stcox var1 var2 var3 etc), I used the "mi predict" command (mi predict hr using mi_est).

However this calculates linear prediction, rather than the relative hazards. Does anyone have any suggestions or solutions to this problem?

I also appreciate the importance of using a training and test set, as suggested in the above document by Dr Newson.

Many thanks,
Dr Brendon Neuen
The George Institute for Global Health

Correlations table: "Correlations greater than ... are significant at p < 0.05"

$
0
0
Hello Stata community:

In papers, I sometimes see a statement such as "Correlations greater than 0.13 are significant at p < 0.05" under the correlations table

Yet, I am still constantly failing to calculate this value (the 0.13). Thus I was wondering whether there is any way of automatically computing in Stata the strength of the correlation at which things become significant at 1%/ 5%/ 10%?

Or would I need to infer these hurdles from just looking at the correlations table?

(The mkcorr output gives a p-value under each correlation number. For example, with the dataset I use, p-values are typically 5% when the correlation number is 0.04. So I am inclined to assume the following: "Correlations greater than 0.04 are significant at p < 0.05")

Yet I was wondering if there is any way to directly calculate this number (and be sure the 0.04 is really the correct value)

Thank you so much & all the best,
Franz

Error exporting R file to Stata

$
0
0
Hi all, need some help here!

So I was using R for my dataset, but not I want to change it to Stata. I have stata 14 in my computer.
SO i used the R haven package and used the comman "write_dta" to make the file a stata file.
However, i am unable to read it on Stata.
I get the following error:
file not Stata format
.dta file contains 2 invalid storage-type codes. File uses code 0 and other invalid codes.
r(610);

Please help if you can. Anything is appreciated!

Merging Annual and Monthly Data Where Monthly Data is Not 12-Month Per Year

$
0
0
Hello,

I am attempting to combine two data sets, one of which has annual data and the other has monthly data for only a few select months per year. however, when I go to do the merge, I keep getting the information that the data between the Master and the Using are not merged (note: this is not an error, just none of the data is merged. See below) This is my first time really dealing with Stata with regards to transforming strings into dates and combining disparate data sets. I will break this post up into multiple parts in an attempt to see where my error lies.

First, I am importing the annual dataset, which is an Excel file, into Stata:
Code:
import excel "C:\Users\jmurp\Desktop\snappolicyindexdata.xls", sheet("Sheet1") firstrow case(lower) allstring

. rename statefipscode state

. destring state, replace
state: all characters numeric; replaced as byte

. gen year2 = yearly(year, "Y")
This gives me the following:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str4 year float year3 byte state str17 unweightedtransactioncostinde
"1996" 1996 1 ".7873089909553528"
"1997" 1997 1 ".9619993567466736"
"1998" 1998 1 ".8730361461639404"
"1999" 1999 1 ".8742402791976929"
"2000" 2000 1 ".7630371451377869"
"2001" 2001 1 ".7088135480880737"
"2002" 2002 1 ".8338995575904846"
"2003" 2003 1 ".8852885365486145"
"2004" 2004 1 "1.331129312515259"
"2005" 2005 1 "2.017022132873535"
"2006" 2006 1 "2.138442039489746"
"2007" 2007 1 "2.138442039489746"
"2008" 2008 1 "2.020892381668091"
"2009" 2009 1 "2.138442039489746"
"2010" 2010 1 "2.138442039489746"
"2011" 2011 1 "2.138442039489746"
"2012" 2012 1 "2.72177529335022" 
"2013" 2013 1 "3.138442039489746"
"2014" 2014 1 "3.138442039489746"
"1996" 1996 2 "1.010496377944946"
"1997" 1997 2 "1.010496377944946"
"1998" 1998 2 ".9321550130844116"
"1999" 1999 2 "1.138442158699036"
"2000" 2000 2 ".9234683513641357"
"2001" 2001 2 ".9556993842124939"
"2002" 2002 2 "1.138442158699036"
"2003" 2003 2 "1.138442158699036"
"2004" 2004 2 "1.804209351539612"
"2005" 2005 2 "2.104795455932617"
"2006" 2006 2 "1.78836977481842" 
"2007" 2007 2 "2.138442039489746"
"2008" 2008 2 "2.138442039489746"
"2009" 2009 2 "2.138442039489746"
"2010" 2010 2 "2.138442039489746"
"2011" 2011 2 "2.138442039489746"
"2012" 2012 2 "2.083318948745728"
"2013" 2013 2 "1.87486743927002" 
"2014" 2014 2 "1.784610509872437"
"1996" 1996 4 ".4647372663021088"
"1997" 1997 4 ".447535902261734" 
"1998" 1998 4 ".4035578370094299"
"1999" 1999 4 ".3449657559394836"
"2000" 2000 4 ".3717425167560577"
"2001" 2001 4 ".4626551866531372"
"2002" 2002 4 ".5120731592178345"
"2003" 2003 4 "1.645817279815674"
"2004" 2004 4 "1.825965404510498"
"2005" 2005 4 "1.702130079269409"
"2006" 2006 4 "1.993517160415649"
"2007" 2007 4 "1.879157066345215"
"2008" 2008 4 "2.048694133758545"
"2009" 2009 4 "2.486948490142822"
"2010" 2010 4 "3.138442039489746"
"2011" 2011 4 "3.138442039489746"
"2012" 2012 4 "3.138442039489746"
"2013" 2013 4 "3.094571590423584"
"2014" 2014 4 "3.050700902938843"
"1996" 1996 5 ".6945005655288696"
"1997" 1997 5 ".7590163350105286"
"1998" 1998 5 ".7152066826820374"
"1999" 1999 5 ".6893616914749146"
"2000" 2000 5 ".900558352470398" 
"2001" 2001 5 ".8908431529998779"
"2002" 2002 5 ".7171991467475891"
"2003" 2003 5 "1.066809296607971"
"2004" 2004 5 "2.086622953414917"
"2005" 2005 5 "2.069708347320557"
"2006" 2006 5 "1.882163643836975"
"2007" 2007 5 "2.101803302764893"
"2008" 2008 5 "1.930241346359253"
"2009" 2009 5 "1.86871075630188" 
"2010" 2010 5 "1.953728437423706"
"2011" 2011 5 "2.764119386672974"
"2012" 2012 5 "2.827212572097778"
"2013" 2013 5 "2.890893220901489"
"2014" 2014 5 "3.006572246551514"
"1996" 1996 6 ".966708242893219" 
"1997" 1997 6 ".8214213848114014"
"1998" 1998 6 ".7084873914718628"
"1999" 1999 6 ".7671941518783569"
"2000" 2000 6 ".8532009124755859"
"2001" 2001 6 ".9936713576316834"
"2002" 2002 6 "1.11318838596344" 
"2003" 2003 6 ".9343733191490173"
"2004" 2004 6 "1.138442158699036"
"2005" 2005 6 "1.056789517402649"
"2006" 2006 6 "1.122111678123474"
"2007" 2007 6 "1.138442158699036"
"2008" 2008 6 ".974398672580719" 
"2009" 2009 6 "1.072202682495117"
"2010" 2010 6 "1.221775531768799"
"2011" 2011 6 "2.138442039489746"
"2012" 2012 6 "2.138442039489746"
"2013" 2013 6 "2.285334348678589"
"2014" 2014 6 "2.940877437591553"
"1996" 1996 8 ".5168286561965942"
"1997" 1997 8 ".5018777847290039"
"1998" 1998 8 ".4973481297492981"
"1999" 1999 8 ".4887761473655701"
"2000" 2000 8 ".4511123597621918"
end
Is this correct so far?

I clean things up a little bit (in order to facilitate the merge, I think):

Code:
drop year
rename year2 year
save "C:\Users\jmurp\Dropbox\GMU\Dissertation\SNAP Costs and Take Up\VCL\tcindex.dta", replace
Now, I want to merge this dataset with another one that looks like this:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(year state stamp_fss_actual)
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 1
517 1 0
517 1 1
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
517 1 1
517 1 0
517 1 0
517 1 1
517 1 1
517 1 0
517 1 0
517 1 0
end
format %tm year
label values state state
label def state 1 "AL", modify
NB: this data set has monthly data for most states from February through December for 2003, 2006, and 2010.

Now, I try to merge the data like this and get the following:

Code:
merge m:1 year state using tcindex

    Result                           # of obs.
    -----------------------------------------
    not matched                       286,654
        from master                   285,685  (_merge==1)
        from using                        969  (_merge==2)

    matched                                 0  (_merge==3)
    -----------------------------------------
Obviously, I am doing something wrong. I am under the impression that merging annual and monthly data is possible. In searching forums, I primarily see folks confusing m:1 and 1:1 merging and getting error messages of "not unique variables." Am I barking up the wrong tree?

Many thanks for the help!

Cutting and pasting graphs into word

$
0
0
I am using stata 16 on a windows 10 machine. Whenever I copy graph files and paste graphs, the text noes not copy with them-e.g. the axis labels, the graph titles, the text in the legend. Has anyone else had this problem with a PC-I know that copying and pasting with a mac was an issue but I cannot find any record of this with a PC.

Looping syntax from R to Stata

$
0
0
Hi all! Seeking all experts in R and Stata for looping!
So I have to extract some country codes from the World Bank data set and input it into my large file of various countries such that each country matches with its respective codes. I have sorted out the loop in R and it has worked it R as well. However, my other analys needs to be done in Stata and I couldn't find a way to convert my R file to Stata. (if anyone knows a way please help)
However, I want to do the same loop in Stata, and want to convert it into Stata language. So please, If anyone is familiar with both the looping ways,
Please guide me the Stata loop for the following R loop:

File1$codewb <- NA
for (i in 1:nrow(File1)){
if(File1$COUNTRY[i] %in% WB$`Country Name`){
index <- which(File1$COUNTRY[i] == WB$`Country Name`)
if(length(index)>0){
File1$codewb_import[i] <- WB$`Country Code`[index]
}else{
File1$codewb_import[i] <- NA
}
}else{
next
}
print(i)
}


Your help is truly very appreciated!

Xtnbreg difference-in-difference.

$
0
0
Dear All,
i am tr
​​​​I want to estimate a difference-in-difference model for count dependent variable. I create a binary 'treat' that is always 1 for units that will be treated and the binary post=1 captures the post treatment variable. The coefficient on treat#post is the classical diff-in-diff estimator.

I would like to calculate the marginal effect of the treatment. So I estimate:
Code:
 
 eststo raw11: xtnbreg sumnalaxone  i.post##i.treat age, fe  exposure(exposure) /*vce(cl > uster studypersonid)*/  /* WORKS*/ note: 1346 groups (2692 obs) dropped because of all zero outcomes  Iteration 0:   log likelihood = -93.131882  Iteration 1:   log likelihood = -86.687569  (not concave) Iteration 2:   log likelihood =  -79.12231  Iteration 3:   log likelihood = -78.471463  Iteration 4:   log likelihood = -78.454974  Iteration 5:   log likelihood = -78.454966   Conditional FE negative binomial regression     Number of obs     =        232 Group variable: studypersonid                   Number of groups  =        116                                                  Obs per group:                                                               min =          2                                                               avg =        2.0                                                               max =          2                                                  Wald chi2(4)      =      80.11 Log likelihood  = -78.454966                    Prob > chi2       =     0.0000  ------------------------------------------------------------------------------  sumnalaxone |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval] -------------+----------------------------------------------------------------       1.post |   1.116119   .3151385     3.54   0.000     .4984593    1.733779      1.treat |   .1157644   .9709931     0.12   0.905    -1.787347    2.018876              |   post#treat |         1 1  |   2.339803   .5109139     4.58   0.000      1.33843    3.341176              |          age |  -.0198788   .0452903    -0.44   0.661     -.108646    .0688885        _cons |  -9.973896   1.557685    -6.40   0.000     -13.0269   -6.920888 ln(exposure) |          1  (exposure) ------------------------------------------------------------------------------  . margins treat, dydx(post)  Average marginal effects                        Number of obs     =        232 Model VCE    : OIM  Expression   : Linear prediction, predict() dy/dx w.r.t. : 1.post  ------------------------------------------------------------------------------              |            Delta-method              |      dy/dx   Std. Err.      z    P>|z|     [95% Conf. Interval] -------------+---------------------------------------------------------------- 1.post       |        treat |           0  |   1.116119   .3151385     3.54   0.000     .4984593    1.733779           1  |   3.455922   .4353058     7.94   0.000     2.602739    4.309106 ------------------------------------------------------------------------------ Note: dy/dx for factor levels is the discrete change from the base level.  . margins treat, at (post=1)  Predictive margins                              Number of obs     =        232 Model VCE    : OIM  Expression   : Linear prediction, predict() at           : post            =           1  ------------------------------------------------------------------------------              |            Delta-method              |     Margin   Std. Err.      z    P>|z|     [95% Conf. Interval] -------------+----------------------------------------------------------------        treat |           0  |   -1.99617   .5378508    -3.71   0.000    -3.050338   -.9420019           1  |   .4593975   .9043628     0.51   0.611    -1.313121    2.231916 ------------------------------------------------------------------------------
I am not sure which marginal effect is the marginal Ieffect of the diff-in-diff estimator? I will be very grateful for any help.
Sincerely,
Sumedha.

psacalc

$
0
0
Hi StataUsers I am running the following regression:
xtreg public_goods opp core turnout t2006 , fe cluster(cod_dane)

and I wanted to check for selection. I want to use psacalc to put some bound on how important selection in the unobservable variables have to be for the estimates ( for app and core) to be entirely attributive to bias. I run the following command :
psacalc beta core, delta(1) rmax(1)
psacalc beta opp, delta(1) rmax(1)

I am not sure if I am doing it right and wanted to ask help interpreting the outputs

Treatment Effect Estimate ----
Estimate Sq. difference Bias changes
from controlled beta direction

Beta -3817.00698 14569527
Alt. sol. 1 0.02296 .00062 Yes
Alt. sol. 2


Inputs from Regressions ----
Coeff. R-Squared

Uncontrolled 0.00677 0.000
Controlled -0.00195 0.009


Other Inputs ----

R_max 1.000
Delta 1.000
Unr. Controls


I wonder if you could guide me on how to approach my concern.
Thanks!

Looping across several datasets

$
0
0
Hi ALL! Need some urgent help !

So I have a main dataset of mine, which has a total of 40 countries, spanning over different years 2000-2018. They have different individual level variables, however since my analysis is multi level, I also want to include a macro level variable like gdp. So what I need to do is, get the gdp values for each country for each year (this is available in Penn World table) and put them into every observation in my main dataset.
Now these gdp values i have in a separate file (can be both excel of stata) with countrynames same as my dataset
Doing it manually is almost impossible, so I Need to create a loop such that the loop extracts the variables from the dataset having gdp values based on the "countrynames" and "year" variables and put in the values for the respective year and country in my main dataset.

I have been able to do it in R, but i am unable to transfer my R file into stata which is needed.
If it is of any help, this is my R code:

for(i in 1:nrow(data)){
if(data$country[i] %in% pwt$country){
index <- which(data$country[i] == pwt$country & data$year[i] == pwt$year)
if(length(index)>0){
data$gdp_import[i] <- pwt$gdp[index]
} else {
data$gdp_import[i] <- NA
}
}else{
next
}
print(i)
}



Any help will be hugely appreciated! thanks!

Univariate analysis

$
0
0
Hello,

So I want to apply this univariate test, subdividing my sample into high and low groups by the mean values of independent variables to report the differences in the dependent variable.

My question's How to subdivide a sample using such condition and what is the command in STATA to do so and apply the test.

My literature reference is Thanatawee, Y. (2019). ‘Foreign Institutional Ownership and Liquidity: Evidence from Thailand’. ABAC Journal, Vol.39, No.4, Forthcoming. pp. 1-21.

Thank you!

Productivity effects

$
0
0
Dear Statalist users,

I am trying to examine the impact of export participation of the firm on firm productivity. To this end, I want to examine how the productivity of the firm changes one year from its participation in export market, two years after participation and so on. To understand if the effect of participating in the export market on its productivity dissipate or accelerate over time. I have an unbalanced panel for the period 2001-2013. TFP is my dependent variable and export status (t1) is my independent variable which is a dummy. I think I need to proceed with a psm-did but I am not able to understand its operation for my dataset.

If I could get some inputs on how to achieve this in stata would be much appreciated

A small sample of my data

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double id float(year t1 ltfp)
 365 2001 0 .39686665
 365 2002 1  .3967393
 365 2003 1  .6374343
 365 2004 0  .6560543
 365 2005 1  .6640503
 365 2006 1  .7698439
 365 2007 0  .8161478
 365 2008 0    .87566
 365 2009 0 1.1369226
 365 2010 0 1.2058983
 365 2011 0 1.0512627
 365 2012 0 1.0222095
 365 2013 0  .9116122
 381 2001 1 .28473413
 381 2002 1  .2790297
 381 2003 1  .4228754
 381 2004 1  .4589705
 381 2005 1   .443521
 381 2006 1  .6932002
 381 2007 1 .51895165
 381 2008 1  .4412919
 381 2009 1  .4278684
 381 2010 1  .4917918
 569 2001 0  .4084495
 569 2002 0 .32361555
 569 2003 0   .312629
 569 2004 0  .3549544
 569 2005 0  .4214703
 569 2006 0  .5034326
 569 2007 0 .52623117
 569 2008 0 .58975697
 569 2009 0 .55094194
 569 2010 0  .3773664
 595 2006 0  .2977381
 595 2007 0  .3644855
 595 2008 0  .3293638
 595 2009 0  .3146657
 595 2010 0  .3185207
 595 2011 0  .4280073
 595 2012 0  .5122329
 595 2013 0  .4275252
 600 2009 0  .7721639
 600 2010 0   .787946
 600 2011 0  .6881346
 600 2012 0  .6645668
 783 2001 0   .729115
 783 2002 0  .7449946
 783 2003 0  .7614059
 783 2004 0   .870962
 783 2005 0  .8693857
 783 2006 0  .8836148
 783 2007 0 1.0283844
 783 2008 0 1.0673563
 783 2009 0 1.2047342
 783 2010 0 1.2074325
 783 2011 0 1.2030094
 783 2012 0  1.209522
 783 2013 0  1.193356
 870 2010 0  .4383901
 934 2004 0  .6618422
 934 2005 0   .677335
 934 2006 0   .698532
 934 2007 0  .6574489
 934 2008 0   .602454
 934 2009 0  .9306454
1120 2001 1 1.0948371
1120 2002 1 1.1048775
1120 2003 1 1.2104284
1120 2004 1 1.1987357
1120 2005 1 1.3653517
1120 2006 1  1.479699
1120 2007 1  1.614259
1120 2008 1 1.8814026
1120 2009 1 2.1619618
1120 2010 1  1.977049
1120 2011 1  2.043859
1120 2012 1  2.134581
1120 2013 1 2.2729049
1621 2007 0  .3721843
1621 2008 0  .4280191
1621 2009 0   .435424
1621 2010 0  .4076315
1621 2011 0  .3898215
1621 2012 0  .4241333
1954 2009 0  .4050439
1954 2010 0 .41772455
2015 2004 0 .17348923
2015 2005 0 .25310284
2015 2006 0  .3803225
2015 2007 0  .4936106
2015 2008 0  .5817891
2015 2009 0  .4436422
2015 2010 0 .42046455
2015 2011 0 .51623964
2015 2012 0  .5415064
2015 2013 0  .4652313
2216 2001 1  .3285122
2216 2002 0  .3717326
2216 2003 0    .40993
2216 2004 0  .3402351
end

Reshaping Datastream Data (Currency) for Stata

$
0
0
I have been trying to transpose Datastream data by date. I know how to do this in SAS but I am having trouble replicating this on STATA. I have provided a dataex sample below


* Example generated by -dataex-. To install: ssc install dataex
clear
input float(date uk australia brazil bulgaria)
-1065 2.7982 . . .
-1037 2.7975 . . .
-1008 2.7875 . . .
-976 2.7912 . . .
-945 2.7918 . . .
-917 2.7912 . . .
-884 2.785 . . .
-854 2.7832 . . .
-823 2.7956 . . .
-792 2.7968 . . .
-763 2.8062 . . .
-731 2.8594 . . .
-700 2.8162 . . .
-672 2.8162 . . .
-641 2.8162 . . .
-611 2.8182 . . .
-581 2.8168 . . .
-550 2.8032 . . .
-519 2.805 . . .
-490 2.8018 . . .
-458 2.8068 . . .
-427 2.8062 . . .
-399 2.8044 . . .
-366 2.8025 . . .
-336 2.8094 . . .
-308 2.8055 . . .
-276 2.8162 . . .
-246 2.8162 . . .
-217 2.8118 . . .
-185 2.8138 . . .
-154 2.8112 . . .
-123 2.8056 . . .
-93 2.8044 . . .
-63 2.8056 . . .
-32 2.8018 . . .
-1 2.8 . . .
28 2.8025 . . .
59 2.8038 . . .
90 2.8075 . . .
119 2.8088 . . .
151 2.8025 . . .
181 2.8069 . . .
210 2.8089 . . .
243 2.8113 . . .
273 2.8106 . . .
304 2.8156 . . .
334 2.8106 . . .
364 2.8038 . . .
396 2.8044 . . .
424 2.7956 . . .
455 2.7975 . . .
483 2.7962 . . .
516 2.7919 . . .
546 2.7881 . . .
577 2.795 . . .
608 2.8056 . . .
637 2.8144 . . .
669 2.815 . . .
699 2.8125 . . .
728 2.8081 . . .
761 2.8119 . . .
789 2.815 . . .
819 2.8138 . . .
850 2.8125 . . .
881 2.81 . . .
910 2.8088 . . .
942 2.805 . . .
973 2.8019 . . .
1001 2.8012 . . .
1034 2.8012 . . .
1064 2.8031 . . .
1095 2.8025 . . .
1126 2.8044 . . .
1154 2.8025 . . .
1183 2.7995 . . .
1215 2.8006 . . .
1246 2.8002 . . .
1274 2.8009 . . .
1307 2.8007 . . .
1337 2.7979 . . .
1368 2.7977 . . .
1399 2.7981 . . .
1428 2.7973 . . .
1460 2.7966 . . .
1491 2.7978 . . .
1519 2.7982 . . .
1551 2.7984 . . .
1581 2.7999 . . .
1610 2.7979 . . .
1642 2.7917 . . .
1673 2.7882 . . .
1704 2.7839 . . .
1734 2.7833 . . .
1764 2.785 . . .
1795 2.7912 . . .
1826 2.7901 1.1118151 . .
1855 2.792 1.1120847 . .
1883 2.7941 1.1135865 . .
1916 2.7905 1.1125064 . .
1946 2.7991 1.1139809 . .
end

I am trying to transpose the data so that the data is sorted by date and there is an ID called 'country' for the column variables which are currently listed as country names. This is how the datastream currency data appears in wide form. I tried doing this using the reshape long command but nothing seems to work. I've also uploaded the raw dataset in csv form if one needs more info about the dataset.

Thank you in advance.

Sub-group meta-analysis in Stata

$
0
0
I have two question:
1: Does Stata allow
sub-group meta-analysis using
mixed effects ? If there is a code available, Please share.
2. How can I get Q-value and its it corresponding p-value for difference between subgroups in meta-analysis. What is the code for that? Many thanks for your support. I am doing a meta-analysis of prevalence studies, but if you have a answer/ code for any other kind of studies, that is fine too.

taking a number from a returned matrix?

$
0
0
Dear All, I run the following xthreg (please search xthreg, and install) command
Code:
xthreg i q1 q2 q3 d1 qd1, rx(cf1) qx(d1) thnum(1) grid(400) trim(0.01) bs(100)
matrix f = e(Fstat)
matrix list f  
/*
f[1,7]
              RSS        MSE      Fstat       Prob     Crit10      Crit5      Crit1
Single  17.781836  .00225201  35.196397          0  12.908204  15.651497  21.814463
*/
outreg2 using "thrpd", word dec(4) adds(F, 35.196397) adec(3) ctitle(linear) replace
Note that you have to (ssc) install outreg2.

My question is: how can I using something like f[1,3] (the is not correct, but what is the correct command?) instead of 35.196397 in the `adds(F, 35.196397)' option?
Viewing all 65060 articles
Browse latest View live