Sunday, May 31, 2020

Converting panel data from WEAKLY balanced to STRONGLY balanced (Bacon decomposition)

Hi Statalisters,

I am working on the Bacon decomposition (using bacondecomp command), which requires a strongly balanced panel.
The panel dataset I am working on was unbalanced, so I performed the following code to convert it into a balanced panel :

Code:
bysort district:  gen nyear=[_N]
tab nyear
keep if nyear==18
After this conversion, I get a "WEAKLY" balanced dataset (according to the xtset id time results), hence the bacondecomp is not working. What transformation can I make to convert the dataset into a "STRONGLY" balanced panel?

I came across this definition of a "strongly balanced" panel: "When the dataset contains a time variable, panels are said to be strongly balanced if each panel contains the same time points, weakly balanced if each panel contains the same number of observations but not the same time points, and unbalanced otherwise." (https://www.stata.com/statalist/arch.../msg00101.html).

However, after the conversion I made, my panel dataset contains 585 districts and each district counts 18 years of data. Why is it still "weakly" balanced? How can I fix this issue?


Please find below a sample the data I am using:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double district float(year lny x)
10101 2000 15.752553 0
10101 2001 16.193884 0
10101 2002 16.471481 0
10101 2003 16.605242 0
10101 2004  17.15857 0
10101 2005  17.22689 0
10101 2006 17.527142 0
10101 2007 18.355291 0
10101 2008 18.943258 0
10101 2009  18.69728 0
10101 2010 18.725645 0
10101 2011 18.640745 0
10101 2012 19.338213 0
10101 2013  19.44976 0
10101 2014 18.819197 0
10101 2015 19.055973 0
10101 2016 19.063976 0
10101 2017  19.14196 0
10103 2000  13.91526 0
10103 2001 13.926852 0
10103 2002 14.537033 0
10103 2003 14.863282 0
10103 2004  15.23191 0
10103 2005  15.82604 0
10103 2006 15.940092 0
10103 2007 16.163109 0
10103 2008 16.602633 0
10103 2009 16.625645 0
10103 2010  16.94231 0
10103 2011 17.234108 0
10103 2012  17.08096 0
10103 2013 17.589808 0
10103 2014 17.507406 0
10103 2015 17.655422 0
10103 2016 17.713999 0
10103 2017  17.98462 0
10105 2000 17.176313 0
10105 2001 17.218447 0
10105 2002  17.22451 0
10105 2003 17.351425 0
10105 2004 18.095589 0
10105 2005 18.538553 0
10105 2006 18.711836 0
10105 2007  19.08575 0
10105 2008  19.27568 0
10105 2009  19.96377 0
10105 2010  19.67612 0
10105 2011 19.225895 0
10105 2012 19.719824 0
10105 2013 19.645073 0
10105 2014 19.229593 0
10105 2015 19.285046 0
10105 2016 19.239407 0
10105 2017   19.5521 0
10107 2000 16.896315 0
10107 2001  17.19038 0
10107 2002  17.37088 0
10107 2003  17.51199 0
10107 2004 18.074612 0
10107 2005 18.092892 0
10107 2006 18.189089 0
10107 2007 18.554443 0
10107 2008  19.16435 0
10107 2009 18.798866 0
10107 2010  19.15159 0
10107 2011  19.48421 0
10107 2012    19.636 0
10107 2013 19.558506 0
10107 2014  19.60922 0
10107 2015 19.698847 0
10107 2016  19.85667 0
10107 2017  20.01661 0
10109 2000 17.288967 0
10109 2001  17.53965 0
10109 2002 17.691305 0
10109 2003 17.912817 0
10109 2004 18.181335 0
10109 2005 18.984133 0
10109 2006 19.162714 0
10109 2007 18.920141 0
10109 2008 18.706972 0
10109 2009  19.65674 0
10109 2010 19.695604 0
10109 2011  20.01785 0
10109 2012  20.11707 0
10109 2013  19.93405 0
10109 2014  19.91495 0
10109 2015 19.680166 0
10109 2016 19.603456 0
10109 2017 19.917625 0
end
Thank you
Marina

Results stop by showing (more)...

I use Stata/IC 14.2 for Mac (64-bit Intel). I'm looking for a solution where Stata can execute commands without a pause. During a longer execution time of Stata commands, my result pauses, and I need to click (more), which is at the bottom of the results window. Can anyone tell me how I can execute Stata without a pause?
​​​​​​​Thanks in advance.

Pause in results window

I use Stata/IC 14.2 for Mac (64-bit Intel). I'm looking for a solution where Stata can execute commands without a pause. During a longer execution time of Stata commands, my result pauses, and I need to click (more), which is at the bottom of the results window. Can anyone tell me how I can execute Stata without a pause?
Thanks in advance.

Descriptive statistics for panel data

Hi Statalist,

I'm struggling to generate the descriptive statistics for my dataset. Here is the example of my data:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID str1 Sex str4 ICD float Cost
 1 "1" "A181"  41578.27
 1 "1" "A181"  2506.016
 2 "1" "A181" 1108.8945
 3 "2" "A181" 1622.8583
 4 "1" "A181" 10756.528
 5 "2" "A181" 1108.8945
 5 "2" "A181" 1110.9061
 6 "1" "A181"  2867.536
 7 "1" "A181"  530.5595
 7 "1" "A181"  9054.715
 7 "1" "A181"   5533.85
 8 "2" "A182" 1145.6062
 8 "2" "A182"  21381.66
 9 "2" "A182" 1145.6062
10 "2" "A182"  4148.777
11 "2" "A182"  25998.42
11 "2" "A182"  4132.329
11 "2" "A182"  5367.452
11 "2" "A182"  5790.894
11 "2" "A182"  6500.989
12 "2" "A182"  7535.454
13 "1" "A182" 1145.6062
13 "1" "A182" 1145.6062
13 "1" "A182"  5161.263
13 "1" "A182" 1145.6062
13 "1" "A182"  2517.015
13 "1" "A182"  2517.015
14 "1" "A183" 1019.3783
15 "2" "A183" 1145.6062
16 "1" "A183" 1682.2006
16 "1" "A183" 11127.165
17 "1" "A183"  1293.459
17 "1" "A183"  921.8157
17 "1" "A183"  4948.536
18 "2" "A183"  4948.536
19 "1" "A183" 1682.2006
19 "1" "A183"  4970.664
20 "2" "A183" 1145.6062
21 "1" "A183" 11212.156
21 "1" "A183" 1235.6254
21 "1" "A183"  39530.45
21 "1" "A183"  921.8157
22 "1" "A183"  10305.93
22 "1" "A183"  4948.536
23 "1" "A183"  4948.536
24 "2" "A184"  17459.18
24 "2" "A184"   6081.57
25 "1" "A184" 1368.8938
26 "2" "A184" 1532.8392
27 "1" "A184" 17041.771
28 "2" "A184" 1532.8392
29 "1" "A184"  1293.459
30 "2" "A184"  5954.839
31 "2" "A185" 1989.9753
32 "1" "A185"  9376.067
33 "1" "A185"  10502.16
33 "1" "A185"  297.2139
33 "1" "A185" 11327.823
33 "1" "A185" 1081.7379
33 "1" "A185"  38024.01
34 "1" "A185"  3589.197
35 "1" "A185" 1466.9594
36 "1" "A185"  23008.18
36 "1" "A185" 2155.4797
36 "1" "A185" 1872.2968
37 "1" "A185" 13298.687
38 "1" "A185" 1012.8406
39 "2" "A185"  782.5124
40 "1" "A185" 1090.2872
41 "2" "A185"  2473.262
end
The result i want to generate is the Total cost and average cost per patient by ICD and by Sex. Something that looks like this:
Total cost Cost per patient
Sex =1 Sex = 2 Sex =1 Sex =2
ICD = A181
A182
A183
A184
A185

Could you kindly show me how to do this? Thank you so much

Appropriate model to use

hello, I have a question on the most appropriate model to use. I have the data set below, I am trying to find whether the treatment had an effect on re_arrests prior to disposition. The treatment affect was applied on 01-January-2018, the problem I have is that the treatment was not applied to every person uniformly. For example someone could have been re_arrested and then given the treatment or re_arrested and then not given the treatment. What model would you recommend to see the effect specified above?

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long caseid int person_id str10(arrest_date dispos_date) byte treat str8 race str1 gender str10 bdate float(re_arrest prior_arrests numeric_bdate AGE numeric_arrest_date numeric_dispos_date time) long(numeric_race numeric_gender) float _diff
57514  1 "2012-01-04" "2012-03-27" 0 "HISPANIC" "F" "1985-07-03" 0  4  9315  26.50513 18996 19079 1 3 1 0
39970  1 "2012-07-11" "2012-10-20" 1 "HISPANIC" "F" "1985-07-03" 0  4  9315 27.022587 19185 19286 1 3 1 1
88413  1 "2013-04-04" "2013-06-22" 0 "HISPANIC" "F" "1985-07-03" 0  4  9315 27.753593 19452 19531 1 3 1 0
    .  1 "2010-04-09" ""           0 ""         ""  ""           .  4     .         . 18361     . 0 . . 0
    .  1 "2008-06-14" ""           0 ""         ""  ""           .  4     .         . 17697     . 0 . . 0
40216  5 "2012-03-31" "2013-03-25" 0 "BLACK"    "M" "1986-09-27" 0  2  9766 25.508556 19083 19442 1 2 2 0
    .  5 "2010-05-20" ""           0 ""         ""  ""           .  2     .         . 18402     . 0 . . 0
    .  5 "2009-06-07" ""           0 ""         ""  ""           .  2     .         . 18055     . 0 . . 0
92255  6 "2012-12-09" "2013-11-09" 0 "BLACK"    "M" "1991-06-07" 0  3 11480 21.508556 19336 19671 1 2 2 0
    .  6 "2009-09-18" ""           0 ""         ""  ""           .  3     .         . 18158     . 0 . . 0
    .  6 "2008-03-16" ""           0 ""         ""  ""           .  3     .         . 17607     . 0 . . 0
    .  6 "2009-01-20" ""           0 ""         ""  ""           .  3     .         . 17917     . 0 . . 0
26516  7 "2012-02-25" "2012-03-26" 0 "HISPANIC" "F" "1994-08-24" 0  0 12654 17.505817 19048 19078 1 3 1 0
 2913  8 "2012-10-06" "2013-12-29" 1 "BLACK"    "M" "1978-04-04" 0  5  6668  34.50787 19272 19721 1 2 2 1
 6304  8 "2013-04-06" "2013-07-07" 0 "BLACK"    "M" "1978-04-04" 1  5  6668  35.00616 19454 19546 1 2 2 0
    .  8 "2011-06-17" ""           0 ""         ""  ""           .  5     .         . 18795     . 0 . . 0
    .  8 "2009-08-05" ""           0 ""         ""  ""           .  5     .         . 18114     . 0 . . 0
    .  8 "2010-06-18" ""           0 ""         ""  ""           .  5     .         . 18431     . 0 . . 0
    .  8 "2011-05-06" ""           0 ""         ""  ""           .  5     .         . 18753     . 0 . . 0
82277  9 "2012-01-12" "2012-11-08" 0 "ASIAN"    "F" "1994-07-11" 0  2 12610 17.505817 19004 19305 1 1 1 0
31881  9 "2013-09-25" "2013-12-29" 1 "ASIAN"    "F" "1994-07-11" 0  2 12610  19.20876 19626 19721 1 1 1 1
    .  9 "2011-02-06" ""           0 ""         ""  ""           .  2     .         . 18664     . 0 . . 0
11354 10 "2013-07-03" "2014-12-13" 1 "HISPANIC" "M" "1984-12-30" 0  3  9130   28.5065 19542 20070 1 3 2 1
    . 10 "2010-10-29" ""           0 ""         ""  ""           .  3     .         . 18564     . 0 . . 0
    . 10 "2009-08-15" ""           0 ""         ""  ""           .  3     .         . 18124     . 0 . . 0
    . 10 "2009-06-03" ""           0 ""         ""  ""           .  3     .         . 18051     . 0 . . 0
49941 11 "2013-03-17" "2013-05-11" 1 "BLACK"    "M" "1987-09-13" 0  3 10117 25.508556 19434 19489 1 2 2 1
    . 11 "2011-05-09" ""           0 ""         ""  ""           .  3     .         . 18756     . 0 . . 0
    . 11 "2011-01-31" ""           0 ""         ""  ""           .  3     .         . 18658     . 0 . . 0
    . 11 "2008-12-16" ""           0 ""         ""  ""           .  3     .         . 17882     . 0 . . 0
59616 12 "2013-06-25" "2013-08-23" 0 "ASIAN"    "F" "1984-12-22" 0  1  9122   28.5065 19534 19593 1 1 1 0
    . 12 "2009-06-03" ""           0 ""         ""  ""           .  1     .         . 18051     . 0 . . 0
88153 13 "2012-10-29" "2013-01-21" 1 "BLACK"    "M" "1963-04-27" 0 10  1212  49.50856 19295 19379 1 2 2 1
40377 13 "2012-11-04" "2013-03-05" 1 "BLACK"    "M" "1963-04-27" 1 10  1212  49.52498 19301 19422 1 2 2 1
39447 13 "2013-07-31" "2013-08-16" 1 "BLACK"    "M" "1963-04-27" 0 10  1212  50.26146 19570 19586 1 2 2 1
    . 13 "2008-09-05" ""           0 ""         ""  ""           . 10     .         . 17780     . 0 . . 0
    . 13 "2010-02-21" ""           0 ""         ""  ""           . 10     .         . 18314     . 0 . . 0
    . 13 "2008-05-16" ""           0 ""         ""  ""           . 10     .         . 17668     . 0 . . 0
    . 13 "2011-04-16" ""           0 ""         ""  ""           . 10     .         . 18733     . 0 . . 0
    . 13 "2011-10-26" ""           0 ""         ""  ""           . 10     .         . 18926     . 0 . . 0
    . 13 "2010-12-28" ""           0 ""         ""  ""           . 10     .         . 18624     . 0 . . 0
    . 13 "2009-09-09" ""           0 ""         ""  ""           . 10     .         . 18149     . 0 . . 0
    . 13 "2011-08-07" ""           0 ""         ""  ""           . 10     .         . 18846     . 0 . . 0
56468 14 "2013-04-05" "2013-10-09" 1 "BLACK"    "M" "1988-10-02" 0  2 10502   24.5065 19453 19640 1 2 2 1
    . 14 "2010-01-01" ""           0 ""         ""  ""           .  2     .         . 18263     . 0 . . 0
    . 14 "2010-09-28" ""           0 ""         ""  ""           .  2     .         . 18533     . 0 . . 0
19842 15 "2012-03-31" "2013-09-08" 1 "BLACK"    "M" "1971-09-27" 0  6  4287  40.50924 19083 19609 1 2 2 1
96126 15 "2012-06-13" "2012-08-15" 0 "BLACK"    "M" "1971-09-27" 1  6  4287  40.71184 19157 19220 1 2 2 0
    . 15 "2008-11-30" ""           0 ""         ""  ""           .  6     .         . 17866     . 0 . . 0
    . 15 "2009-02-06" ""           0 ""         ""  ""           .  6     .         . 17934     . 0 . . 0
    . 15 "2010-12-01" ""           0 ""         ""  ""           .  6     .         . 18597     . 0 . . 0
    . 15 "2008-01-22" ""           0 ""         ""  ""           .  6     .         . 17553     . 0 . . 0
    . 15 "2008-12-31" ""           0 ""         ""  ""           .  6     .         . 17897     . 0 . . 0
95551 16 "2012-05-23" "2012-08-02" 1 "HISPANIC" "M" "1975-11-19" 0  4  5801  36.50924 19136 19207 1 3 2 1
    . 16 "2008-08-23" ""           0 ""         ""  ""           .  4     .         . 17767     . 0 . . 0
    . 16 "2009-12-11" ""           0 ""         ""  ""           .  4     .         . 18242     . 0 . . 0
    . 16 "2008-05-30" ""           0 ""         ""  ""           .  4     .         . 17682     . 0 . . 0
    . 16 "2008-01-25" ""           0 ""         ""  ""           .  4     .         . 17556     . 0 . . 0
97880 17 "2012-05-22" "2012-06-15" 1 "HISPANIC" "M" "1982-11-18" 0  3  8357 29.508556 19135 19159 1 3 2 1
    . 17 "2009-06-01" ""           0 ""         ""  ""           .  3     .         . 18049     . 0 . . 0
    . 17 "2011-03-17" ""           0 ""         ""  ""           .  3     .         . 18703     . 0 . . 0
    . 17 "2011-09-30" ""           0 ""         ""  ""           .  3     .         . 18900     . 0 . . 0
37756 18 "2012-01-10" "2013-06-03" 1 "BLACK"    "M" "1974-07-09" 0 10  5303 37.505817 19002 19512 1 2 2 1
26780 18 "2012-04-05" "2013-01-26" 1 "BLACK"    "M" "1974-07-09" 1 10  5303 37.741272 19088 19384 1 2 2 1
57949 18 "2012-04-18" "2012-05-27" 0 "BLACK"    "M" "1974-07-09" 1 10  5303 37.776867 19101 19140 1 2 2 0
    . 18 "2009-08-07" ""           0 ""         ""  ""           . 10     .         . 18116     . 0 . . 0
    . 18 "2008-10-06" ""           0 ""         ""  ""           . 10     .         . 17811     . 0 . . 0
    . 18 "2010-01-08" ""           0 ""         ""  ""           . 10     .         . 18270     . 0 . . 0
    . 18 "2009-11-22" ""           0 ""         ""  ""           . 10     .         . 18223     . 0 . . 0
    . 18 "2009-11-13" ""           0 ""         ""  ""           . 10     .         . 18214     . 0 . . 0
    . 18 "2008-12-25" ""           0 ""         ""  ""           . 10     .         . 17891     . 0 . . 0
    . 18 "2009-11-02" ""           0 ""         ""  ""           . 10     .         . 18203     . 0 . . 0
    . 18 "2010-05-02" ""           0 ""         ""  ""           . 10     .         . 18384     . 0 . . 0
62439 19 "2013-07-08" "2013-09-16" 1 "WHITE"    "M" "1987-01-04" 0  2  9865  26.50787 19547 19617 1 4 2 1
39548 19 "2013-09-20" "2014-08-29" 0 "WHITE"    "M" "1987-01-04" 0  2  9865  26.71047 19621 19964 1 4 2 0
    . 19 "2008-02-16" ""           0 ""         ""  ""           .  2     .         . 17578     . 0 . . 0
end
format %td numeric_bdate
format %td numeric_arrest_date
format %td numeric_dispos_date
label values numeric_race numeric_race
label def numeric_race 1 "ASIAN", modify
label def numeric_race 2 "BLACK", modify
label def numeric_race 3 "HISPANIC", modify
label def numeric_race 4 "WHITE", modify
label values numeric_gender numeric_gender
label def numeric_gender 1 "F", modify
label def numeric_gender 2 "M", modify

Interpreting outputs from "raschjmle" command

Hi!
I am doing my research on Rasch analysis for measuring knowledge. I am using Stata-14 to construct a scale by rasch analysis. Recently I have learnt about "raschjmle" command and got some outputs. But I did not find any interpretation for "raschjmle" in the help document. Would you please suggest me where I can find resources for interpreting this command? Thanks in advance for your help.

Regards
Zobaida

Counting number of variables across groups

Hi,

I have three variables KeyEventDates KeyEventHistory KeyEventDetails that I am splitting into several columns. I want to check if the number of columns created when each of these variables is split is the same (ideally, the split for each of the three variables should generate the same number of columns). Is there a way to write a loop or generate a temporary variable that will do so?

Thanks,
Karishma

Could I include the survey data of "prefer not to say"?

Dear friends, I collect survey data with categorical outcome variables whose outcome includes "prefer not to say". Original data is very small and less than 80. I am confused if I could include that outcome or set "prefer not to say" as a new category using the command, like
Code:
i.var1
. Thank you!

Difference in Difference

Hello, I'm trying to do a difference in difference for the data below. The treatment starts after January-2012-01 but when I try running the regression is says the indicator variable and the treatment variable are correlated and drops them. I want the response variable to the re_arrests which is dichotomous, the treat variable is the treatment effect and the treatment as written above starts on January-2012-01


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long caseid int person_id str10(arrest_date dispos_date) byte treat str8 race str1 gender str10 bdate float(distance re_arrest prior_arrests numeric_bdate AGE numeric_arrest_date numeric_dispos_date) long(numeric_race numeric_gender)
57514  1 "2012-01-04" "2012-03-27" 0 "HISPANIC" "F" "1985-07-03"    . 0 4  9315  26.50513 18996 19079 3 1
39970  1 "2012-07-11" "2012-10-20" 1 "HISPANIC" "F" "1985-07-03"  106 0 4  9315 27.022587 19185 19286 3 1
88413  1 "2013-04-04" "2013-06-22" 0 "HISPANIC" "F" "1985-07-03"  166 0 4  9315 27.753593 19452 19531 3 1
    .  1 "2008-06-14" ""           . ""         ""  ""              . . 4     .         . 17697     . . .
    .  1 "2010-04-09" ""           . ""         ""  ""              . . 4     .         . 18361     . . .
40216  5 "2012-03-31" "2013-03-25" 0 "BLACK"    "M" "1986-09-27"    . 0 2  9766 25.508556 19083 19442 2 2
    .  5 "2010-05-20" ""           . ""         ""  ""              . . 2     .         . 18402     . . .
    .  5 "2009-06-07" ""           . ""         ""  ""              . . 2     .         . 18055     . . .
92255  6 "2012-12-09" "2013-11-09" 0 "BLACK"    "M" "1991-06-07"    . 0 3 11480 21.508556 19336 19671 2 2
    .  6 "2009-09-18" ""           . ""         ""  ""              . . 3     .         . 18158     . . .
    .  6 "2008-03-16" ""           . ""         ""  ""              . . 3     .         . 17607     . . .
    .  6 "2009-01-20" ""           . ""         ""  ""              . . 3     .         . 17917     . . .
26516  7 "2012-02-25" "2012-03-26" 0 "HISPANIC" "F" "1994-08-24"    . 0 0 12654 17.505817 19048 19078 3 1
 2913  8 "2012-10-06" "2013-12-29" 1 "BLACK"    "M" "1978-04-04"    . 0 5  6668  34.50787 19272 19721 2 2
 6304  8 "2013-04-06" "2013-07-07" 0 "BLACK"    "M" "1978-04-04" -267 1 5  6668  35.00616 19454 19546 2 2
    .  8 "2009-08-05" ""           . ""         ""  ""              . . 5     .         . 18114     . . .
    .  8 "2011-05-06" ""           . ""         ""  ""              . . 5     .         . 18753     . . .
    .  8 "2010-06-18" ""           . ""         ""  ""              . . 5     .         . 18431     . . .
    .  8 "2011-06-17" ""           . ""         ""  ""              . . 5     .         . 18795     . . .
82277  9 "2012-01-12" "2012-11-08" 0 "ASIAN"    "F" "1994-07-11"    . 0 2 12610 17.505817 19004 19305 1 1
31881  9 "2013-09-25" "2013-12-29" 1 "ASIAN"    "F" "1994-07-11"  321 0 2 12610  19.20876 19626 19721 1 1
    .  9 "2011-02-06" ""           . ""         ""  ""              . . 2     .         . 18664     . . .
11354 10 "2013-07-03" "2014-12-13" 1 "HISPANIC" "M" "1984-12-30"    . 0 3  9130   28.5065 19542 20070 3 2
    . 10 "2009-08-15" ""           . ""         ""  ""              . . 3     .         . 18124     . . .
    . 10 "2010-10-29" ""           . ""         ""  ""              . . 3     .         . 18564     . . .
    . 10 "2009-06-03" ""           . ""         ""  ""              . . 3     .         . 18051     . . .
end
format %td numeric_bdate
format %td numeric_arrest_date
format %td numeric_dispos_date
label values numeric_race numeric_race
label def numeric_race 1 "ASIAN", modify
label def numeric_race 2 "BLACK", modify
label def numeric_race 3 "HISPANIC", modify
label values numeric_gender numeric_gender
label def numeric_gender 1 "F", modify
label def numeric_gender 2 "M", modify

Merging Two Data Set

Hello Stata Users,
I am trying to combine two different data sets according to the variables "Area" and "Year". While observations of these variables are common in both data sets, after using the merge command, observations of the same year and the same country appear in different rows. The reason for this is that, in a dataset, the names of the countries appear first in the cell, followed by a space.
I am adding a sample from one of the data sets below. Besides, I am adding the list of Area according to tag after merging. How can I deal with this problem? Thank you in advance.

Best,


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str35 Area int Year float(avr_precip avr_temp)
" Afghanistan" 1961  355969.9  276361.9
" Afghanistan" 1962  415947.5  230001.1
" Afghanistan" 1963  481006.8  328412.2
" Afghanistan" 1964  262749.5  243936.5
" Afghanistan" 1965  426870.7 203707.33
" Afghanistan" 1966  446330.1 281000.16
" Afghanistan" 1967  487800.4 262055.25
" Afghanistan" 1968  423439.6 261638.83
" Albania"     1961 509769.75    302613
" Albania"     1962  347457.3 245861.33
" Albania"     1963  392791.9  202664.4
" Albania"     1964    372516    247544
" Albania"     1965  342288.5    344300
" Albania"     1966  406166.6  297721.6
" Albania"     1967    374308 312650.25
" Albania"     1968  447654.3 230648.33
end
merge m:m Area Year using "C:\Users\simay\Desktop\all_merged_atfp_climat e_an alysis(no_zero_coundum).dta"
(note: variable Area was str35, now str52 to accommodate using data's values)

Result # of obs.
-----------------------------------------
not matched 23,802
from master 10,080 (_merge==1)
from using 13,722 (_merge==2)

matched 840 (_merge==3)
-----------------------------------------


+----------------------------------------------+
| Area |
|----------------------------------------------|
1. | Afghanistan |
57. | Albania |
113. | Algeria |
169. | Andorra |
225. | Angola |
|----------------------------------------------|
281. | Antigua and Barbuda |
337. | Argentina |
393. | Armenia |
449. | Australia |
505. | Austria |
|----------------------------------------------|
561. | Azerbaijan |
617. | Bahamas |
673. | Bahrain |
729. | Bangladesh |
785. | Barbados |
|----------------------------------------------|
841. | Belarus |
897. | Belgium |
953. | Belize |
1009. | Benin |
1065. | Bhutan |
|----------------------------------------------|
1121. | Bolivia |
1177. | Bosnia and Herzegovina |
1233. | Botswana |
1289. | Brazil |
1345. | Brunei |
|----------------------------------------------|
1401. | Bulgaria |
1457. | Burkina Faso |
1513. | Burundi |
1569. | Cambodia |
1625. | Cameroon |
|----------------------------------------------|
1681. | Canada |
1737. | Cape Verde |
1793. | Central African Republic |
1849. | Chad |
1905. | Chile |
|----------------------------------------------|
1961. | China |
2017. | Colombia |
2073. | Comoros |
2129. | Costa Rica |
2185. | Croatia |
|----------------------------------------------|
2241. | Cuba |
2297. | Cyprus |
2353. | Czech Republic |
2409. | Denmark |
2465. | Djibouti |
|----------------------------------------------|
2521. | Dominica |
2577. | Dominican Republic |
2633. | Ecuador |
2689. | Egypt |
2745. | El Salvador |
|----------------------------------------------|
2801. | Equatorial Guinea |
2857. | Eritrea |
2913. | Estonia |
2969. | Ethiopia |
3025. | Faroe Islands |
|----------------------------------------------|
3081. | Fiji |
3137. | Finland |
3193. | France |
3249. | Gabon |
3305. | Gambia |
|----------------------------------------------|
3361. | Georgia |
3417. | Germany |
3473. | Ghana |
3529. | Greece |
3585. | Greenland |
|----------------------------------------------|
3641. | Grenada |
3697. | Guatemala |
3753. | Guinea |
3809. | Guinea-Bissau |
3865. | Guyana |
|----------------------------------------------|
3921. | Haiti |
3977. | Honduras |
4033. | Hungary |
4089. | Iceland |
4145. | India |
|----------------------------------------------|
4201. | Indonesia |
4257. | Iraq |
4313. | Ireland |
4369. | Israel |
4425. | Italy |
|----------------------------------------------|
4481. | Jamaica |
4537. | Japan |
4593. | Jordan |
4649. | Kazakhstan |
4705. | Kenya |
|----------------------------------------------|
4761. | Kiribati |
4817. | Korea |
4873. | Kuwait |
4929. | Latvia |
4985. | Lebanon |
|----------------------------------------------|
5041. | Lesotho |
5097. | Liberia |
5153. | Libya |
5209. | Liechtenstein |
5265. | Lithuania |
|----------------------------------------------|
5321. | Luxembourg |
5377. | Macedonia |
5433. | Madagascar |
5489. | Malawi |
5545. | Malaysia |
|----------------------------------------------|
5601. | Maldives |
5657. | Mali |
5713. | Malta |
5769. | Marshall Islands |
5825. | Mauritania |
|----------------------------------------------|
5881. | Mauritius |
5937. | Mexico |
5993. | Moldova |
6049. | Monaco |
6105. | Mongolia |
|----------------------------------------------|
6161. | Morocco |
6217. | Mozambique |
6273. | Namibia |
6329. | Nepal |
6385. | Netherlands |
|----------------------------------------------|
6441. | New Caledonia |
6497. | New Zealand |
6553. | Nicaragua |
6609. | Niger |
6665. | Nigeria |
|----------------------------------------------|
6721. | Northern Mariana Islands |
6777. | Norway |
6833. | Oman |
6889. | Pakistan |
6945. | Palau |
|----------------------------------------------|
7001. | Panama |
7057. | Papua New Guinea |
7113. | Paraguay |
7169. | Peru |
7225. | Philippines |
|----------------------------------------------|
7281. | Poland |
7337. | Portugal |
7393. | Puerto Rico |
7449. | Qatar |
7505. | Romania |
|----------------------------------------------|
7561. | Rwanda |
7617. | Samoa |
7673. | Sao Tome and Principe |
7729. | Saudi Arabia |
7785. | Senegal |
|----------------------------------------------|
7841. | Seychelles |
7897. | Sierra Leone |
7953. | Singapore |
8009. | Slovakia |
8065. | Slovenia |
|----------------------------------------------|
8121. | Solomon Islands |
8177. | Somalia |
8233. | South Africa |
8289. | South Sudan |
8345. | Spain |
|----------------------------------------------|
8401. | Sri Lanka |
8457. | St. Kitts and Nevis |
8513. | St. Lucia |
8569. | St. Vincent and the Grenadines |
8625. | Sudan |
|----------------------------------------------|
8681. | Suriname |
8737. | Swaziland |
8793. | Sweden |
8849. | Switzerland |
8905. | Tajikistan |
|----------------------------------------------|
8961. | Thailand |
9017. | Togo |
9073. | Tonga |
9129. | Trinidad and Tobago |
9185. | Tunisia |
|----------------------------------------------|
9241. | Turkey |
9297. | Turkmenistan |
9353. | Tuvalu |
9409. | Uganda |
9465. | Ukraine |
|----------------------------------------------|
9521. | United Arab Emirates |
9577. | United Kingdom |
9633. | Uruguay |
9689. | Uzbekistan |
9745. | Vanuatu |
|----------------------------------------------|
9801. | Venezuela |
9857. | Vietnam |
9913. | Yemen |
9969. | Zambia |
10025. | Zimbabwe |
|----------------------------------------------|
10081. | Congo |
10137. | Congo, Dem. Rep. |
10193. | Côte d'Ivoire |
10249. | Iran (Islamic Republic of) |
10305. | Kyrgyz Rep. |
|----------------------------------------------|
10361. | Lao People's Democratic Republic |
10417. | Micronesia (Federated States of) |
10473. | Montenegro |
10529. | Myanmar |
10585. | Russian Federation |
|----------------------------------------------|
10641. | Serbia |
10697. | Syrian Arab Republic |
10753. | Timor-Leste |
10809. | United Republic of Tanzania |
10865. | United States of America |
|----------------------------------------------|
10921. | Afghanistan |
10984. | Albania |
11049. | Algeria |
11118. | American Samoa |
11178. | Andorra |
|----------------------------------------------|
11238. | Angola |
11299. | Anguilla |
11364. | Antigua and Barbuda |
11425. | Argentina |
11488. | Armenia |
|----------------------------------------------|
11549. | Aruba |
11609. | Australia |
11677. | Austria |
11739. | Azerbaijan |
11800. | Bahamas |
|----------------------------------------------|
11864. | Bahrain |
11924. | Bangladesh |
12000. | Barbados |
12061. | Belarus |
12122. | Belgium |
|----------------------------------------------|
12219. | Belgium-Luxembourg |
12275. | Belize |
12337. | Benin |
12397. | Bermuda |
12458. | Bhutan |
|----------------------------------------------|
12518. | Bolivia |
12578. | Bosnia and Herzegovina |
12638. | Botswana |
12698. | Brazil |
12768. | British Virgin Islands |
|----------------------------------------------|
12828. | Brunei Darussalam |
12888. | Bulgaria |
12950. | Burkina Faso |
13012. | Burundi |
13072. | Cambodia |
|----------------------------------------------|
13132. | Cameroon |
13192. | Canada |
13285. | Cape Verde |
13341. | Cayman Islands |
13401. | Central African Republic |
|----------------------------------------------|
13461. | Chad |
13523. | Channel Islands |
13583. | Chile |
13653. | China |
13758. | China, Taiwan Province of |
|----------------------------------------------|
13836. | China, mainland |
13894. | Colombia |
13965. | Comoros |
14039. | Costa Rica |
14102. | Croatia |
|----------------------------------------------|
14162. | Cuba |
14227. | Cyprus |
14288. | Czech Republic |
14348. | Czechoslovakia |
14411. | Democratic People's Republic of Korea |
|----------------------------------------------|
14471. | Denmark |
14532. | Djibouti |
14592. | Dominica |
14653. | Dominican Republic |
14715. | Ecuador |
|----------------------------------------------|
14781. | Egypt |
14846. | El Salvador |
14909. | Equatorial Guinea |
14969. | Eritrea |
15029. | Estonia |
|----------------------------------------------|
15089. | Ethiopia |
15150. | Ethiopia, former |
15206. | Faroe Islands |
15266. | Fiji |
15331. | Finland |
|----------------------------------------------|
15392. | France |
15471. | French Guiana |
15529. | French Polynesia |
15590. | Gabon |
15650. | Gambia |
|----------------------------------------------|
15712. | Georgia |
15772. | Germany |
15846. | Ghana |
15908. | Gibraltar |
15968. | Greece |
|----------------------------------------------|
16041. | Greenland |
16101. | Grenada |
16161. | Guadeloupe |
16221. | Guam |
16281. | Guatemala |
|----------------------------------------------|
16345. | Guinea |
16405. | Guinea-Bissau |
16467. | Guyana |
16527. | Haiti |
16593. | Honduras |
|----------------------------------------------|
16655. | Hong Kong SAR, China |
16714. | Hungary |
16775. | Iceland |
16835. | India |
16927. | Indonesia |
|----------------------------------------------|
17037. | Iraq |
17098. | Ireland |
17159. | Isle of Man |
17219. | Israel |
17281. | Italy |
|----------------------------------------------|
17360. | Jamaica |
17435. | Japan |
17534. | Jordan |
17595. | Kazakhstan |
17656. | Kenya |
|----------------------------------------------|
17717. | Kiribati |
17777. | Kuwait |
17845. | Latvia |
17905. | Lebanon |
17967. | Lesotho |
|----------------------------------------------|
18027. | Lesser Antilles |
18083. | Liberia |
18143. | Libya |
18204. | Liechtenstein |
18264. | Lithuania |
|----------------------------------------------|
18324. | Luxembourg |
18384. | Macao SAR, China |
18444. | Macedonia |
18503. | Madagascar |
18564. | Malawi |
|----------------------------------------------|
18624. | Malaysia |
18684. | Maldives |
18744. | Mali |
18806. | Malta |
18866. | Marshall Islands |
|----------------------------------------------|
18926. | Martinique |
18986. | Mauritania |
19048. | Mauritius |
19108. | Mayotte |
19166. | Mexico |
|----------------------------------------------|
19244. | Moldova |
19304. | Mongolia |
19370. | Montserrat |
19397. | Morocco |
19462. | Mozambique |
|----------------------------------------------|
19533. | Namibia |
19593. | Nauru |
19653. | Nepal |
19714. | Netherlands |
19778. | Netherlands Antilles (former) |
|----------------------------------------------|
19838. | New Caledonia |
19903. | New Zealand |
19969. | Nicaragua |
20032. | Niger |
20099. | Nigeria |
|----------------------------------------------|
20160. | Northern Mariana Islands |
20220. | Norway |
20282. | Oman |
20342. | Pakistan |
20416. | Palau |
|----------------------------------------------|
20476. | Panama |
20536. | Papua New Guinea |
20599. | Paraguay |
20659. | Peru |
20732. | Philippines |
|----------------------------------------------|
20816. | Poland |
20879. | Portugal |
20941. | Puerto Rico |
21006. | Qatar |
21066. | Republic of Korea |
|----------------------------------------------|
21132. | Romania |
21207. | Rwanda |
21268. | Réunion |
21326. | Saint Helena, Ascension and Tristan da Cunha |
21384. | Saint Pierre and Miquelon |
|----------------------------------------------|
21442. | Samoa |
21502. | Sao Tome and Principe |
21562. | Saudi Arabia |
21622. | Senegal |
21688. | Serbia and Montenegro |
|----------------------------------------------|
21744. | Seychelles |
21804. | Sierra Leone |
21864. | Singapore |
21924. | Slovakia |
21984. | Slovenia |
|----------------------------------------------|
22044. | Solomon Islands |
22106. | Somalia |
22166. | South Africa |
22229. | South Sudan |
22289. | Spain |
|----------------------------------------------|
22357. | Sri Lanka |
22418. | St. Kitts and Nevis |
22480. | St. Lucia |
22540. | St. Vincent and the Grenadines |
22602. | Sudan |
|----------------------------------------------|
22662. | Sudan (former) |
22721. | Suriname |
22781. | Swaziland |
22839. | Sweden |
22901. | Switzerland |
|----------------------------------------------|
22968. | Tajikistan |
23030. | Thailand |
23094. | Togo |
23154. | Tonga |
23215. | Trinidad and Tobago |
|----------------------------------------------|
23276. | Tunisia |
23337. | Turkey |
23426. | Turkmenistan |
23486. | Turks and Caicos Islands |
23546. | Tuvalu |
|----------------------------------------------|
23607. | USSR |
23678. | Uganda |
23740. | Ukraine |
23800. | United Arab Emirates |
23860. | United Kingdom |
|----------------------------------------------|
23925. | United States Virgin Islands |
24038. | Uruguay |
24098. | Uzbekistan |
24158. | Vanuatu |
24221. | Venezuela |
|----------------------------------------------|
24284. | Vietnam |
24346. | West Bank and Gaza |
24406. | Yemen |
24466. | Yugoslav SFR |
24523. | Zambia |
|----------------------------------------------|
24583. | Zimbabwe |
+----------------------------------------------+




Graphs after forecasts

Hi everyone!

I try to make forecasts four hourly electricity load. I use the forecasts option from Stata's manuals. However i cannot obtain the appropriate graphs, i.e. forecast errors, actual vs forecast load .
forecast solve, begin(tc(05apr2019 04:00:00))

Computing dynamic forecasts for model sm1load.
----------------------------------------------
Starting period: 05apr2019 04:00:00
Ending period: 16may2019 19:00:00
Forecast prefix: f_

05apr2019 04:00:00: ..........
05apr2019 05:00:00: ..........
05apr2019 06:00:00: ...........
05apr2019 07:00:00: ...........
05apr2019 08:00:00: ...........
05apr2019 09:00:00: ..........
05apr2019 10:00:00: ..........
05apr2019 11:00:00: ..........
05apr2019 12:00:00: ..........
05apr2019 13:00:00: ..........
05apr2019 14:00:00: ..........
05apr2019 15:00:00: ..........
05apr2019 16:00:00: ..........
05apr2019 17:00:00: ..........
05apr2019 18:00:00: ..........
05apr2019 19:00:00: ..........
05apr2019 20:00:00: ..........
05apr2019 21:00:00: ..........
05apr2019 22:00:00: ..........
05apr2019 23:00:00: ..........
06apr2019 00:00:00: ..........
06apr2019 01:00:00: ..........
06apr2019 02:00:00: ..........
06apr2019 03:00:00: ..........
06apr2019 04:00:00: ..........
06apr2019 05:00:00: ..........
06apr2019 06:00:00: ..........
06apr2019 07:00:00: ..........
06apr2019 08:00:00: ..........
06apr2019 09:00:00: ..........
06apr2019 10:00:00: ..........
06apr2019 11:00:00: ..........
06apr2019 12:00:00: ..........
06apr2019 13:00:00: ..........
06apr2019 14:00:00: ..........
06apr2019 15:00:00: ..........
06apr2019 16:00:00: ..........
06apr2019 17:00:00: ..........
06apr2019 18:00:00: .........

That's what appears after solving. How can I obtain the forecast values and graphs? Does anyone know the right commands? Thank you in advance for your help.

Graphs after forecasts

Hi everyone!

I try to make dynamic forecasts for hourly load predictions.. I use the forecast commands and I get the following results:
solve, begin(tc(05apr2019 04:00:00))

Computing dynamic forecasts for model sm1load.
----------------------------------------------
Starting period: 05apr2019 04:00:00
Ending period: 16may2019 19:00:00
Forecast prefix: f_

05apr2019 04:00:00: ..........
05apr2019 05:00:00: ..........
05apr2019 06:00:00: ...........
05apr2019 07:00:00: ...........
05apr2019 08:00:00: ...........
05apr2019 09:00:00: ..........
05apr2019 10:00:00: ..........
05apr2019 11:00:00: ..........
05apr2019 12:00:00: ..........
05apr2019 13:00:00: ..........
05apr2019 14:00:00: ..........
05apr2019 15:00:00: ..........
05apr2019 16:00:00: ..........
05apr2019 17:00:00: ..........
05apr2019 18:00:00: ..........
05apr2019 19:00:00: ..........
05apr2019 20:00:00: ..........
05apr2019 21:00:00: ..........
05apr2019 22:00:00: ..........
05apr2019 23:00:00: ..........
06apr2019 00:00:00: ..........
06apr2019 01:00:00: ..........
06apr2019 02:00:00: ..........
06apr2019 03:00:00: ..........
06apr2019 04:00:00: ..........
06apr2019 05:00:00: ..........
06apr2019 06:00:00: ..........
06apr2019 07:00:00: ..........
06apr2019 08:00:00: ..........
06apr2019 09:00:00: ..........

However, I don't know how to obtain the appropriate graphs, For, instance forecast vs actual obvervations and forecast errors etc.. Does anyoene knows the commands? Furthermore how can I get the forecasted values? Thank you in advance for your help!

create variable names from a variable value, and then group by id

Hello Statalisters,

thank you in advance for considering the following.

I'm trying to creating new variables names from a single variables value, and to assign these variables values taken from another variable.

My data appears as the following:

id count class
1 1 c1
1 2 c2
1 3 c3
2 11 c1
2 22 c2
2 33 c3

I want class too form names of new variables, where each of these variables assume the value of the associated count. More specifically, i want the transformation to result in the following:

id c1 c2 c3
1 1 2 3
2 11 22 33

I've seen some previous posts (e.g., https://www.statalist.org/forums/for...o-one-stacking) but I don't seem to be able to apply these to my data

My code is as follows:

input id count str5 class
1 1 c1
1 2 c2
1 3 c3
2 11 c1
2 22 c2
2 33 c3
end

levelsof class, local(ccc)

foreach newclass in `ccc' {
gen `newclass' = count if class == "`newclass'"
rename `newclass' ccc`newclass'
}

list
----
My output:
+--------------------------------------------+
| id count class cccc1 cccc2 cccc3 |
|--------------------------------------------|
1. | 1 1 c1 1 . . |
2. | 1 2 c2 . 2 . |
3. | 1 3 c3 . . 3 |
4. | 2 11 c1 11 . . |
5. | 2 22 c2 . 22 . |
|--------------------------------------------|
6. | 2 33 c3 . . 33 |
+--------------------------------------------+

I can probably transform through other steps using Collapse or Sum for my example data. However, the number of classes in my actual data is quite large, making use of these somewhat difficult.

Does anyone have suggestions on how to convert my data to
id c1 c2 c3
1 1 2 3
2 11 22 33
?

thanks again,
​​​​​​​Ed

Validating and Cross Checking Stata Code

Hi Everyone,

I have done an analysis of the Demographic and Health Survey data for my research project. Because this is my first serious analysis, I am not sure whether the analysis (Stata Codes) I did is completely correct and the results of my analysis truly reflect my research objectives. I do not want my paper to be rejected just because of the wrong analysis.

Is anyone here know of any statistical consulting firm, freelancer, website or organization which/who can validate the codes of my analysis?

Many Thanks,

Pavan

Identify all user-written commands used in a do-file

Hi,

I've a paper accepted at a journal and have to send my do-files for replication purposes.
I'd like to include all the ados used in this do-file which were not pre-installed, like ivreg2 etc.

Is there any chance to find this out?

Best,
Mike

Local inside program

Hi,

I cannot seem to make the following program use the local inside it.

MWE:

Code:
sysuse auto,clear
* Reg program
capture program drop reg_1
program reg_1
reg price mpg `reg_var' 
end
local reg_var "rep78 headroom"
reg_1
The program does not read the local reg_var.
Does anybody know why?

difference between predcit and predict, xb

Hi, i know that predict yh, xb gives you a linear prediction using X'b. But how does the command predict by itself (without ,xb) does?

Im thinking about a probit/logit model.

thank you.



difference between predcit and predict, xb

Sorry for the multiple posts, please delete this.

difference between predictand predict, xb

Hi, i know that predict yh, xb gives you a linear prediction using X'b. But how does the command predict by itself (without ,xb) does?

Im thinking about a probit/logit model.

thank you.

How to drop duplicates under certain conditions for a subset of observations?

Hi all,
I am trying to drop duplicate observations under certain conditions.
My data looks something like the following:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str8 childid float round
"IN010001" 2
"IN010001" 3
"IN010001" 4
"IN010001" 4
"IN010001" 4
"IN010001" 5
"IN010001" 5
"IN010001" 5
"IN010002" 2
"IN010002" 3
"IN010002" 4
"IN010002" 4
"IN010002" 4
"IN010002" 5
"IN010002" 5
"IN010002" 5
"IN010003" 2
"IN010003" 3
"IN010003" 4
"IN010003" 4
"IN010003" 4
"IN010003" 5
"IN010003" 5
"IN010003" 5
"IN010004" 2
"IN010004" 3
"IN010004" 4
"IN010004" 4
"IN010004" 4
"IN010004" 5
"IN010004" 5
"IN010004" 5
"IN010005" 2
"IN010005" 3
"IN010005" 4
"IN010005" 4
"IN010005" 4
"IN010005" 5
"IN010005" 5
"IN010005" 5
"IN010006" 2
"IN010006" 3
"IN010007" 2
"IN010007" 3
"IN010007" 4
"IN010007" 4
"IN010007" 4
"IN010007" 5
"IN010007" 5
"IN010007" 5
"IN010008" 2
"IN010008" 3
"IN010008" 4
"IN010008" 4
"IN010008" 4
"IN010008" 5
"IN010008" 5
"IN010008" 5
"IN010009" 2
"IN010009" 3
"IN010009" 4
"IN010009" 4
"IN010009" 4
"IN010009" 5
"IN010009" 5
"IN010009" 5
"IN010010" 2
"IN010010" 3
"IN010010" 4
"IN010010" 4
"IN010010" 4
"IN010010" 5
"IN010010" 5
"IN010010" 5
"IN010011" 2
"IN010011" 3
"IN010011" 4
"IN010011" 4
"IN010011" 4
"IN010011" 5
"IN010011" 5
"IN010011" 5
"IN010012" 2
"IN010012" 3
"IN010012" 4
"IN010012" 4
"IN010012" 4
"IN010012" 5
"IN010012" 5
"IN010012" 5
"IN010013" 2
"IN010013" 3
"IN010013" 4
"IN010013" 4
"IN010013" 4
"IN010013" 5
"IN010013" 5
"IN010013" 5
"IN010014" 2
"IN010014" 3
end
As can be seen, for rounds 4 and 5, each childid appears thrice. I want to drop the duplicates for rounds 4 and 5 so that each childid appears only once, as in rounds 2 and 3.
I have tried the following code:
Code:
duplicates tag childid, gen(flag)
drop if flag & (round==4|round==5)
which removes all observations from rounds 4 and 5.

I have also tried
Code:
forvalues i=4/5{
duplicates tag childid, gen(flag) if round==`i'
drop if flag
}
.
which generates the error
Code:
option if not allowed
What I am looking for is duplicates drop code that works only on rounds 4 and 5 but have been unable to figure it out.

Any help from the community would be greatly appreciated.

Regards,
Titir

fractional probit with sample selection using CMP

Hello everyone!
I am planning to run a fractional response model with sample selection. I wonder if it is possible to do so with a CMP command by David Roodman ?
In a thread https://www.statalist.org/forums/for...l-added-to-cmp , it is mentioned that fractional model has been added to cmp. And in the original paper(Fitting fully observed recursive mixed-process models with cmp) by the author , commands for various probit models with heckman are given. My questions are:
1)can they be extended to frcational response model?
is a command like this correct?:
cmp (part = EDU DISTANCE GENDER i.Year* ) (SHARE= EDU GENDER i.Year* ), ind( $cmp_probit $cmp_frac )
where DISTANCE is the exclusion restriction for the model?
2) If the command is correct, can it be used in panel data by adding 'cluster(id)'?
Thanks

Reshaping data for tabplot

Array Hello,

How do I reshape the following data to be able to use the tabplot command?
Basically I have 8 different symptoms like "hoste", which means coughing. Each symptom variable can be rated from 0 to 5. I can see that I probably need a new variable for the frequencies, and maybe some additional reshaping. The dataset can be used from this address: "https://ift.tt/2TWWCsx"
Thank you in advance.



Matrix not found error after just listing the matrix

Dear All,
Sorry for a very lengthy post, but I am trying to explain the problem comprehensively. I am attempting to estimate an event-study to evaluate the effect of a set of policy changes. I want to see whether the policies had a differential effect in rural areas and thus include event-time dummies with interaction for an indicator for rural.

My data looks something like:

Code:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double dex byte(rural ds_FirstConfirmedCase_1 ds_FirstConfirmedCase_2) long county_d float date long state_d
121.1581 0 1 0 1558 21965 43
 74.4307 1 1 0  714 21937 18
 52.4785 1 0 0 1829 22009 47
 31.8169 1 0 0 1846 22019 47
 35.5682 0 0 0 1169 22029 33
 53.1551 0 0 0 1624 21998 43
 34.6536 1 0 0  576 22029 16
 56.2691 1 0 0 1024 21990 26
213.1753 0 0 0  241 21970 10
 91.7799 1 0 0  633 21976 17
 63.2084 0 0 0  669 22021 18
 72.0173 0 1 0 1538 21957 41
  47.946 0 0 0 1600 21996 43
  66.612 0 0 0 1686 22007 44
 42.2578 0 0 0 1431 22033 38
102.8714 0 1 0  883 21944 24
275.4706 0 0 0  316 21987 11
 71.4822 0 0 0  250 21999 10
 39.3476 0 0 0 1916 22022 48
 44.3592 1 1 0 1333 21964 36
 89.0314 0 1 0 1862 21977 47
 38.3352 0 0 0 1560 22007 43
 29.2048 0 0 0 1107 21996 31
 24.7918 1 0 0 1168 22000 33
106.3698 0 1 0  508 21969 15
 86.6527 1 1 0  297 21970 11
 83.5633 1 0 0  239 22033 10
 96.2455 0 1 0  538 21962 15
 38.4943 1 0 0 1296 22020 36
301.6847 1 1 0 1262 21953 34
 68.3879 0 0 0 1863 22029 47
 30.8103 0 0 0  205 22036  7
 23.5787 1 0 0  771 21984 20
 24.5118 1 0 0  498 22004 15
 26.4736 1 1 0 1974 21950 50
 70.9563 0 0 0 1116 22008 32
  44.122 0 0 0 1069 22035 28
 51.8799 1 1 0  709 21965 18
 59.7964 1 0 0    9 21983  1
 42.5701 1 0 0 1578 21997 43
 56.6789 1 0 0 1146 21989 33
  41.445 0 0 0 1314 22010 36
 52.1805 1 0 0 1664 22015 44
 94.2434 1 1 0 1461 21968 39
 45.5013 1 1 0  625 21942 17
 97.7381 1 0 0 1370 22020 37
108.7252 0 1 0  806 21956 22
182.1346 1 1 0  503 21939 15
 65.0327 0 1 0  760 21965 20
 236.405 0 0 0 1660 21984 44
157.5645 1 1 0  493 21960 15
 80.0207 1 1 0  547 21954 15
 64.1631 0 0 0  841 22035 23
 15.2419 1 1 0  767 21955 20
 93.2231 1 0 0  569 21973 16
 38.5618 0 0 0 1744 22004 44
  95.841 0 1 0 1670 21941 44
 75.7985 1 1 0  112 21955  4
 28.3126 0 0 0  387 22035 12
107.8034 1 0 0 1265 21972 34
  36.874 0 0 0  586 22008 16
 32.3622 0 0 0  442 22017 14
 99.8781 1 0 0 1077 21982 29
 100.907 0 1 0 1548 21944 42
 68.8354 1 0 0 1949 22036 49
 52.2867 0 0 0  356 22019 11
 272.789 0 1 0  642 21946 17
 42.6058 1 0 0 1578 22006 43
100.9722 1 1 0   42 21961  1
 16.5106 1 0 0  400 22016 13
 23.5787 0 0 0  143 21995  5
 66.8417 0 0 0 1620 21994 43
 22.4997 1 1 0 1485 21969 39
 26.1053 0 0 0 1152 21995 33
 93.6394 0 1 0 1096 21955 31
 34.3344 0 0 0 1094 22031 31
 80.7337 1 1 0   67 21953  3
 44.9029 1 1 0 1943 21944 49
 87.6698 1 1 0 1987 21936 50
 66.7398 1 0 0 1593 22025 43
121.8709 0 0 0 1372 21992 37
 23.8923 1 0 0  881 22009 24
 33.3761 0 0 0  907 22005 24
 59.8646 1 1 0  889 21970 24
 82.9484 1 1 0 1639 21983 44
 52.2777 1 1 0 1477 21951 39
 60.7247 0 0 0  668 21995 18
140.2874 0 1 0  216 21949 10
 71.7848 1 1 0 1872 21942 47
159.0968 0 0 0  891 21976 24
 68.3546 1 1 0  312 21942 11
172.3867 1 1 0 1567 21959 43
 44.7498 1 0 0  641 22001 17
121.0611 0 0 0 1402 22015 37
 74.2227 0 1 0 1787 21943 45
 34.9993 1 0 0   85 21997  4
 214.749 0 1 0  782 21959 21
645.7959 0 1 0 1876 21938 47
410.3959 0 0 1 1687 21959 44
 89.4759 1 1 0 1077 21970 29
end
format %d date
label values county_d county_d
label def county_d 9 "01019", modify
label def county_d 42 "01093", modify
label def county_d 67 "04007", modify
label def county_d 85 "05021", modify
label def county_d 112 "05113", modify
label def county_d 143 "06047", modify
label def county_d 205 "09007", modify
label def county_d 216 "12005", modify
label def county_d 239 "12063", modify
label def county_d 241 "12071", modify
label def county_d 250 "12089", modify
label def county_d 297 "13069", modify
label def county_d 312 "13107", modify
label def county_d 316 "13117", modify
label def county_d 356 "13225", modify
label def county_d 387 "15009", modify
label def county_d 400 "16057", modify
label def county_d 442 "17097", modify
label def county_d 493 "18031", modify
label def county_d 498 "18041", modify
label def county_d 503 "18051", modify
label def county_d 508 "18061", modify
label def county_d 538 "18133", modify
label def county_d 547 "18151", modify
label def county_d 569 "19029", modify
label def county_d 576 "19055", modify
label def county_d 586 "19085", modify
label def county_d 625 "20021", modify
label def county_d 633 "20059", modify
label def county_d 641 "20113", modify
label def county_d 642 "20121", modify
label def county_d 668 "21049", modify
label def county_d 669 "21059", modify
label def county_d 709 "21207", modify
label def county_d 714 "21217", modify
label def county_d 760 "23001", modify
label def county_d 767 "23015", modify
label def county_d 771 "23025", modify
label def county_d 782 "24017", modify
label def county_d 806 "25017", modify
label def county_d 841 "26081", modify
label def county_d 881 "27021", modify
label def county_d 883 "27027", modify
label def county_d 889 "27047", modify
label def county_d 891 "27053", modify
label def county_d 907 "27109", modify
label def county_d 1024 "29157", modify
label def county_d 1069 "31155", modify
label def county_d 1077 "32007", modify
label def county_d 1094 "34005", modify
label def county_d 1096 "34009", modify
label def county_d 1107 "34031", modify
label def county_d 1116 "35013", modify
label def county_d 1146 "36037", modify
label def county_d 1152 "36053", modify
label def county_d 1168 "36089", modify
label def county_d 1169 "36091", modify
label def county_d 1262 "37189", modify
label def county_d 1265 "37195", modify
label def county_d 1296 "39043", modify
label def county_d 1314 "39081", modify
label def county_d 1333 "39125", modify
label def county_d 1370 "40047", modify
label def county_d 1372 "40051", modify
label def county_d 1402 "40143", modify
label def county_d 1431 "41067", modify
label def county_d 1461 "42063", modify
label def county_d 1477 "42097", modify
label def county_d 1485 "42117", modify
label def county_d 1538 "45087", modify
label def county_d 1548 "46099", modify
label def county_d 1558 "47015", modify
label def county_d 1560 "47019", modify
label def county_d 1567 "47035", modify
label def county_d 1578 "47059", modify
label def county_d 1593 "47099", modify
label def county_d 1600 "47115", modify
label def county_d 1620 "47163", modify
label def county_d 1624 "47173", modify
label def county_d 1639 "48025", modify
label def county_d 1660 "48099", modify
label def county_d 1664 "48123", modify
label def county_d 1670 "48145", modify
label def county_d 1686 "48199", modify
label def county_d 1687 "48201", modify
label def county_d 1744 "48395", modify
label def county_d 1787 "49045", modify
label def county_d 1829 "51083", modify
label def county_d 1846 "51143", modify
label def county_d 1862 "51187", modify
label def county_d 1863 "51191", modify
label def county_d 1872 "51590", modify
label def county_d 1876 "51660", modify
label def county_d 1916 "53067", modify
label def county_d 1943 "54067", modify
label def county_d 1949 "54097", modify
label def county_d 1974 "55065", modify
label def county_d 1987 "55097", modify
label values state_d state_d
label def state_d 1 "01", modify
label def state_d 3 "04", modify
label def state_d 4 "05", modify
label def state_d 5 "06", modify
label def state_d 7 "09", modify
label def state_d 10 "12", modify
label def state_d 11 "13", modify
label def state_d 12 "15", modify
label def state_d 13 "16", modify
label def state_d 14 "17", modify
label def state_d 15 "18", modify
label def state_d 16 "19", modify
label def state_d 17 "20", modify
label def state_d 18 "21", modify
label def state_d 20 "23", modify
label def state_d 21 "24", modify
label def state_d 22 "25", modify
label def state_d 23 "26", modify
label def state_d 24 "27", modify
label def state_d 26 "29", modify
label def state_d 28 "31", modify
label def state_d 29 "32", modify
label def state_d 31 "34", modify
label def state_d 32 "35", modify
label def state_d 33 "36", modify
label def state_d 34 "37", modify
label def state_d 36 "39", modify
label def state_d 37 "40", modify
label def state_d 38 "41", modify
label def state_d 39 "42", modify
label def state_d 41 "45", modify
label def state_d 42 "46", modify
label def state_d 43 "47", modify
label def state_d 44 "48", modify
label def state_d 45 "49", modify
label def state_d 47 "51", modify
label def state_d 48 "53", modify
label def state_d 49 "54", modify
label def state_d 50 "55", modify
------------------ copy up to and including the previous line ------------------
Then I estimate the regression, estimate the total effect in rural areas using margins and try to save the output in a matrix to graph. Its lengthy (so I am showing a subset of the code and attaching the rest) but seems to be going well until I get an error that the estimates matrix is not found right after its listed.:

Code:
*Fit the event study regressions
foreach T in FirstConfirmedCase SchoolClose StayAtHome FirstDeath{
    gen b_`T' = .
 gen upper_`T' = .
 gen lower_`T' = .
 gen br_`T' = .
 gen upperr_`T' = .
 gen lowerr_`T' = .
 gen bi_`T' = .
 gen upperi_`T' = .
 gen loweri_`T' = .

 reghdfe dex rural##(ds_`T'_1-ds_`T'_20 ds_`T'_22-ds_`T'_43), ///
 absorb(county_d date state_d##date, save) cluster(county_d)
 
 estimates store c`T'
 
 local row = 0
   
    forvalues t = 2(1)20 {
        local ++row
        qui replace b_`T' = _b[1.ds_`T'_`t'] in `row'
        qui replace upper_`T' = _b[1.ds_`T'_`t'] + 1.96*_se[1.ds_`T'_`t'] in `row'
        qui replace lower_`T' = _b[1.ds_`T'_`t']-  1.96*_se[1.ds_`T'_`t'] in `row'
  qui replace br_`T' = _b[1.rural#1.ds_`T'_`t'] in `row'
        qui replace upperr_`T' = _b[1.rural#1.ds_`T'_`t'] + 1.96*_se[1.rural#1.ds_`T'_`t'] in `row'
        qui replace lowerr_`T' = _b[1.rural#1.ds_`T'_`t']-  1.96*_se[1.rural#1.ds_`T'_`t'] in `row'
    }
    local ++row
    qui replace b_`T'= 0 in `row'
 qui replace br_`T'= 0 in `row'
    forvalues t = 22/42 {
        local ++row
        qui replace b_`T'  = _b[1.ds_`T'_`t'] in `row'
        qui replace upper_`T' = _b[1.ds_`T'_`t'] + 1.96*_se[1.ds_`T'_`t'] in `row'
        qui replace lower_`T' = _b[1.ds_`T'_`t'] - 1.96*_se[1.ds_`T'_`t'] in `row'
  qui replace br_`T'  = _b[1.rural#1.ds_`T'_`t'] in `row'
        qui replace upperr_`T' = _b[1.rural#1.ds_`T'_`t'] + 1.96*_se[1.rural#1.ds_`T'_`t'] in `row'
        qui replace lowerr_`T' = _b[1.rural#1.ds_`T'_`t'] - 1.96*_se[1.rural#1.ds_`T'_`t'] in `row'
    }

 local ys 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
 foreach y of local ys{
 qui reghdfe dex rural##(ds_`T'_1-ds_`T'_20 ds_`T'_22-ds_`T'_43), ///
 absorb(county_d date state_d##date, save) cluster(county_d)
 margins, expression(_b[1.ds_`T'_`y']+_b[1.rural#1.ds_`T'_`y']) post
  /*qui*/ esttab, ci
  mat ci`T'`y'= r(coefs)
}
mat ci`T'21=(0,0,0,0)
mat ci`T' = ci`T'1\ci`T'2\ci`T'3\ci`T'4\ci`T'5\ci`T'6\ci`T'7\ci`T'8\ci`T'9\ci`T'10\ci`T'11\ci`T'12\ci`T'13\ci`T'14\ci`T'15\ci`T'16\ci`T'17\ci`T'18\ci`T'19\ci`T'20\ci`T'21\ci`T'22\ci`T'23\ci`T'24\ci`T'25\ci`T'26\ci`T'27\ci`T'28\ci`T'29\ci`T'30\ci`T'31\ci`T'32\ci`T'33\ci`T'34\ci`T'35\ci`T'36\ci`T'37\ci`T'38\ci`T'39\ci`T'40\ci`T'41\ci`T'42\ci`T'43
mat list ci`T'
mat colnames ci`T' ="tot_rural`T'" "tot_rural_uci`T'" "tot_rural_lci`T'" "tot_rural_p`T'"
matrix rownames ci`T'= "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29" "30" "31" "32" "33" "34" "35" "36" "37" "38" "39" "40" "41" "42" "43"
//mat ci`T'p= ci`T''

forvalues ti = 2(1)20 {
        local ++row
        qui replace bi_`T' = ci`T'[`ti',1] in `row'
        qui replace upperi_`T' = ci`T'[`ti',2] in `row'
        qui replace loweri_`T' = ci`T'[`ti',3] in `row'
    }
    local ++row
    qui replace bi_`T'= 0 in `row'
    forvalues t = 22/42 {
        local ++row
        qui replace bi_`T' = ci`T'[`ti',1] in `row'
        qui replace upperi_`T' = ci`T'[`ti',2] in `row'
        qui replace loweri_`T' = ci`T'[`ti',3] in `row'
    }

 
   # delimit ;
    twoway
        (rarea upper_`T' lower_`T' timeG if inrange(timeG, -20,20), color(gs12%35))
        (connected b_`T' timeG if inrange(timeG, -20,-2),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
  (connected b_`T' timeG if inrange(timeG, 0,20),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
        (function y = 0, range(-20 20) lcolor(gs10)),
        xline(-.5 , lwidth(2.2) lcolor(gs10) )
        xsize(4) ysize(2)
        xtitle("") ytitle("Mixing Index", size(vsmall))
  graphregion(color(white))
        xlabel(-20(5)20, labsize(small))
  ylabel(/*-400(150)200*/, labsize(small) )  
        legend(off)
        graphregion(margin(r+5))
        title("`Title`T''", pos(11) size(3.5))
        name(`T', replace)
     ;
    # delimit cr
  graph export "$plotdir/ES_`var'.png",  replace  width(4000) 
 
 # delimit ;
    twoway
        (rarea upperr_`T' lowerr_`T' timeG if inrange(timeG, -20,20), color(gs12%35))
        (connected br_`T' timeG if inrange(timeG, -20,-2),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
  (connected br_`T' timeG if inrange(timeG, 0,20),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
        (function y = 0, range(-20 20) lcolor(gs10)),
        xline(-.5 , lwidth(2.2) lcolor(gs10) )
        xsize(4) ysize(2)
        xtitle("") ytitle("Mixing Index", size(vsmall))
  graphregion(color(white))
        xlabel(-20(5)20, labsize(small))
  ylabel(/*-400(150)200*/, labsize(small) )  
        legend(off)
        graphregion(margin(r+5))
        title("`Title`T''", pos(11) size(3.5))
        name(r`T', replace)
     ;
    # delimit cr
  graph export "$plotdir/ESr_`var'.png",  replace  width(4000) 
 
 # delimit ;
    twoway
        (rarea upperi_`T' loweri_`T' timeG if inrange(timeG, -20,20), color(gs12%35))
        (connected bi_`T' timeG if inrange(timeG, -20,-2),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
  (connected bi_`T' timeG if inrange(timeG, 0,20),
            mcolor(cranberry) lwidth(medium) lcolor(cranberry) msize(small))
        (function y = 0, range(-20 20) lcolor(gs10)),
        xline(-.5 , lwidth(2.2) lcolor(gs10) )
        xsize(4) ysize(2)
        xtitle("") ytitle("Mixing Index", size(vsmall))
  graphregion(color(white))
        xlabel(-20(5)20, labsize(small))
  ylabel(/*-400(150)200*/, labsize(small) )  
        legend(off)
        graphregion(margin(r+5))
        title("`Title`T''", pos(11) size(3.5))
        name(i`T', replace)
     ;
    # delimit cr
  graph export "$plotdir/ESi_`var'.png",  replace  width(4000) 
 
 rename __hdfe2__ datefe`T'
 
}
The event-study runs, the margins all run to estimate the full effect in rural areas (see attached) and the matrix ciFirstConfirmedCase is generated and then I get the following error (confusing since the matrix was just generated and listed):
Code:
ciFirstConfirmedCase[43,4]
           active:     active:     active:     active:
                b        ci_l        ci_u           p
_cons  -33.992753  -46.021658  -21.963848   3.047e-08
_cons  -19.201088  -32.343054  -6.0591215   .00418846
_cons  -24.223434  -42.416965  -6.0299033   .00906595
_cons  -19.428991  -32.896787  -5.9611955   .00469138
_cons  -17.670705  -33.584708  -1.7567012   .02953143
_cons   -10.69152  -26.332381   4.9493411   .18032351
_cons  -21.091456  -34.776707  -7.4062037   .00252224
_cons  -15.791958  -29.443427  -2.1404892   .02337327
_cons   .78847254  -14.131996   15.708941   .91750715
_cons  -.21585848  -15.417481   14.985764   .97779702
_cons  -6.0163747  -19.340196    7.307447   .37614467
_cons   10.879587   -4.749868   26.509043   .17246646
_cons  -.82162958  -14.251595   12.608335   .90455578
_cons  -7.8447947  -20.425515    4.735926   .22165129
_cons  -2.0624241  -13.437858   9.3130093    .7223263
_cons   4.5547978   -9.334093   18.443689   .52037908
_cons   3.5513728   -8.942559   16.045305   .57744853
_cons  -1.1591633  -16.744876   14.426549   .88410352
_cons  -3.3511476  -16.348078   9.6457827   .61330602
_cons   3.2054066  -23.388244   29.799057   .81324652
   r1           0           0           0           0
_cons  -5.0311321  -22.144137   12.081873    .5644672
_cons  -3.3002542  -15.772785   9.1722769   .60403274
_cons  -19.825333  -31.621159  -8.0295082   .00098728
_cons  -8.1466876  -22.243875   5.9504996   .25736021
_cons  -9.6166914  -23.845398   4.6120148   .18527996
_cons  -7.3184411  -19.616744   4.9798619     .243481
_cons  -8.9264227  -22.261508    4.408663   .18952432
_cons  -13.739964  -26.698042  -.78188667    .0376884
_cons  -10.077364  -25.529255   5.3745276    .2011638
_cons  -21.923598  -36.939063  -6.9081342   .00421401
_cons  -17.711232  -32.069384  -3.3530799   .01561993
_cons  -10.102648  -24.816717   4.6114217   .17839704
_cons  -19.011671  -33.147993  -4.8753489   .00839099
_cons  -20.020774  -31.996916  -8.0446331   .00105097
_cons  -5.5561248  -20.200059   9.0878092   .45709473
_cons  -20.287334  -35.070798  -5.5038709   .00715255
_cons  -27.383867  -43.912183  -10.855552    .0011653
_cons   -23.66688  -37.357931  -9.9758301   .00070386
_cons   -24.01003  -41.201916  -6.8181439   .00619519
_cons  -24.553526  -40.959911  -8.1471416   .00335434
_cons  -31.183961  -45.877887  -16.490035   .00003189
_cons  -38.747589  -51.936516  -25.558662   8.504e-09
ciFirstConfirmedCase not found
r(111);

end of do-file

r(111);

.
But, i see ciFirstConfirmedCase listed just above the error...so not sure what happens. Will be very grateful for any help offered and apologies again for the very lengthy post.
Sincerely,
Sumedha.

command tabcount is unrecognized

Hi everyone,
I'm learning stata these days. I was trying to use tabcount but I get the following error:
"command tabcount is unrecognized"

What can I do? I get the same for tabchi.

Thank you very much.

Mattia

Applying weights to mixed-effects logistic regression model

Hello Statalist,

I am trying to add weights to my mixed-effects logistic regression model. I could use regression commands melogit or meqrlogit, but I don't know how to add weights to either.

So far, I have been working with simple logistic regression, and weighting with svyset and svy: . The difference is very significant depending on whether or not I weight the models. I expect the weighting to be similarly important with a mixed-effects logistic regression.

However, svyset and svy: do not seem to work in combination with melogit or meqrlogit (although I am not sure, as I find the help entry to be a bit confusing here).

So my question is whether somebody can tell me how to combine my weighting with either melogit or meqrlogit.

Here is the data and command information you may require:

My weighting variable
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double Compwt
2.09944
 .41773
 .36181
 .87289
 .41773
 .87289
 .41773
 .87289
 .36181
 .87289
 .36181
 .87289
 .87289
2.09944
 .36181
 .52707
 .87289
 .52707
 .87289
 .52707
 .87289
2.09944
 .87289
 .87289
2.09944
 .87289
2.09944
 .87289
 .87289
 .52707
 .36181
 .52707
 .52707
2.09944
2.09944
2.09944
 .52707
 .87289
 .87289
 .87289
2.09944
 .87289
 .87289
 .87289
 .36181
 .36181
 .87289
 .54305
 .52707
 .52707
 .87289
 .87289
2.09944
 .87289
 .87289
 .87289
 .87289
 .87289
 .87289
 .41773
 .36181
2.09944
2.09944
 .52707
 .87289
 .52707
 .41773
 .87289
 .52707
 .36181
2.09944
2.09944
 .36181
 .87289
 .52707
 .52707
2.09944
 .52707
2.09944
 .52707
 .52707
 .87289
 .87289
 .87289
 .87289
 .87289
 .41773
 .87289
 .54305
 .87289
2.09944
 .87289
2.09944
 .36181
 .36181
 .52707
 .87289
 .87289
 .52707
 .36181
end
label values Compwt Compwt
My dependent variable
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float childcare
0
0
1
1
1
0
1
1
1
1
1
0
0
0
1
0
0
0
1
1
1
0
0
1
0
1
0
1
1
0
0
1
0
1
1
1
0
0
0
1
0
0
0
1
1
1
1
1
0
1
0
1
.
1
0
1
0
0
0
.
1
0
0
1
0
1
1
1
1
1
1
0
1
0
1
0
0
1
1
1
0
1
0
0
0
1
1
1
1
0
1
0
1
1
1
1
1
1
0
1
end
label values childcare childcare
label def childcare 0 "Not provided", modify
label def childcare 1 "Provided", modify
My group variable
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float p_regime
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
end
label values p_regime p_regime
label def p_regime 1 "Pre-K only", modify
label def p_regime 2 "Both", modify
My weighting command
Code:
 svyset [pweight = Compwt]
My weighted logit command (which works perfectly)
Code:
 svy: logit childcare i.p_regime i.skillprofile gdp size fem_execs

Many thanks for your time and consideration.

How to calculate mean and 95%CI of willingness to pay (Discrete choice experiment)

Hi everyone

I am new in the forum. Hope one of you with expertise in choice experiments method can advice me.
My name is Poonyawee. I am using StataIC 16 for data analysis. I developed a questionnaire using choice experiments to estimate patients preference on osteoarthritis treatment. My attributes included pain relief, slow disease progression, gastrointestinal side effect, kidney side effect, cardiovascular side effect and cost of treatment. I ran MNL and this is my results.

mlogit y pain slow gi kid cv cost

Iteration 0: log likelihood = -1412.7494
Iteration 1: log likelihood = -1233.8452
Iteration 2: log likelihood = -1233.6762
Iteration 3: log likelihood = -1233.6762

Multinomial logistic regression Number of obs = 2,040
LR chi2(6) = 358.15
Prob > chi2 = 0.0000
Log likelihood = -1233.6762 Pseudo R2 = 0.1268

------------------------------------------------------------------------------
y | Coef. Std. Err. z P>|z| [95% Conf. Interval]
-------------+----------------------------------------------------------------
0 | (base outcome)
-------------+----------------------------------------------------------------
1 |
pain | .00819 .0029905 2.74 0.006 .0023287 .0140514
slow | .0129133 .0023527 5.49 0.000 .0083021 .0175244
gi | -.0127163 .0016884 -7.53 0.000 -.0160255 -.0094071
kid | -.0522486 .0046489 -11.24 0.000 -.0613604 -.0431369
cv | -.0542176 .0050274 -10.78 0.000 -.0640712 -.0443641
cost | -.0003448 .0000979 -3.52 0.000 -.0005367 -.0001529
_cons | 1.166027 .2011958 5.80 0.000 .7716902 1.560363
------------------------------------------------------------------------------

My problem is that I would like to know how to calculate mean and 95%CI of WTP. I try to use many syntax such as mixlogitwtp, nlcom but STATA show the error code. Please give me an advice.

Thank you in advance
Poonyawee

Saturday, May 30, 2020

Unique Geographic Identifiers from Pooled Data Samples

Hello,

I am using pooled data from selected samples of DHS data. Each sample(country) has a set of unique regions - sometimes ranging from 2 to 10. Given that these regions are different from country to country, I want to create a single variable that harmonizes all the region codes across the sample pool.

Below is the dofile I am using to generate the harmonized regionID.



Code:

set more off

* Create variable ct that is a string of the country value (e.g., Nigeria, Senegal)
decode(country), gen(ct)
levelsof ct, local(ctstring)


* Create a temporary variable that combines all the country-specific region codes.
egen region_temp = rowmax(geo_*)

* Use the temporary variable you created above, plus the country variable, to
* create a unique number for each region in your pooled dataset.  
gen subnational = country*100 + region_temp

* The next command creates string variables for each geographic code.
* Find the geo_ variables in your variable list. Substitute your first and last
* geo variables for geoalt_ke2014 and geo_ug2016, respectively:
foreach var of varlist geo_ao2015_2015 - geo_ls2004_2014 {
    decode `var', gen(`var'str)
}

* The following code create idregion, a single variable with values for every sample.  
egen region_label_t_gen = concat(geo*str)
gen region_label_gen = ct + " " + substr(region_label_t_gen,1,100)
egen idregion = group(region_label_gen)

* This look attaches the proper region labels to regionid.
sort subnational
lab def subnational_gen 1 "temp", replace
levelsof(idregion), local(levels)

foreach 1 of local levels {
    gen temp = ""
    replace temp = region_label_gen if idregion *== `1'
    levelsof(temp), local(templabel)
    lab def reg_label_gen `1' `templabel', modify
    drop temp
}

label values idregion reg_label_gen
label variable idregion "Subnational regions"

* Get rid of the temporary variables
drop subnational geo*str region_temp region_label_t_gen region_label_gen

fre idregion



When I run it, I get the following error:



Code:
. foreach 1 of local levels {
  2.         gen temp = ""
  3.         replace temp = region_label_gen if idregion *== `1'
  4.         levelsof(temp), local(templabel)
  5.         lab def reg_label_gen `1' `templabel', modify
  6.         drop temp
  7. }
(55 missing values generated)
idregion* invalid name
r(198);

end of do-file

r(198);



Thanks for your attention - CY


Below is Sample of my data from dataex - note the number of regions in the extract is limited to 5, though it is more in the full dataset.



Code:

* Example generated by -dataex-. To install: ssc install dataex
clear
input double sample float country byte(geo_ao2015_2015 geo_bi2010_2016 geo_ch2014_2014 geo_cm2004_2011 geo_cg2014_2014 geo_et2000_2016 geo_gb2012_2012 geo_gh1988_2014 geo_gu2018_2018 geo_ke1989_2014 geo_ls2004_2014) long v001 int(v002 v003)
 2401  24  2 .  . . .  . . . . .  .  57    8  5
 2401  24  9 .  . . .  . . . . .  . 542    7  2
 2401  24 14 .  . . .  . . . . .  . 174   18  6
 2401  24 14 .  . . .  . . . . .  .  61   14  2
 2401  24 18 .  . . .  . . . . .  . 608    7  1
10803 108  . 1  . . .  . . . . .  . 140 8259  3
10803 108  . 3  . . .  . . . . .  . 488 4492  2
10803 108  . 3  . . .  . . . . .  . 549 5502  2
10803 108  . 4  . . .  . . . . .  . 153 5157  2
10803 108  . 4  . . .  . . . . .  . 358 5234  2
12004 120  . .  . 5 .  . . . . .  . 550   17  1
12004 120  . .  . 5 .  . . . . .  .  64   24  1
12004 120  . .  . 6 .  . . . . .  . 105   15  1
12004 120  . .  . 8 .  . . . . .  . 165   10  4
12004 120  . .  . 8 .  . . . . .  . 467   22  1
14803 148  . . 19 . .  . . . . .  . 523    6  9
23104 231  . .  . . .  3 . . . .  . 327  212  2
23104 231  . .  . . .  4 . . . .  . 518  264  2
23104 231  . .  . . .  7 . . . .  . 223  451  3
23104 231  . .  . . .  7 . . . .  . 466  166  5
23104 231  . .  . . . 10 . . . .  . 211  385  2
28806 288  . .  . . .  . . 3 . .  . 148   20  2
28806 288  . .  . . .  . . 4 . .  . 410   19  1
28806 288  . .  . . .  . . 4 . .  . 176    6  2
28806 288  . .  . . .  . . 6 . .  . 236   10  1
28806 288  . .  . . .  . . 7 . .  .  12   30  2
32404 324  . .  . . .  . . . 1 .  . 362   70  3
32404 324  . .  . . .  . . . 1 .  . 158   58  3
32404 324  . .  . . .  . . . 3 .  . 244   30  1
32404 324  . .  . . .  . . . 5 .  .  21   49  1
32404 324  . .  . . .  . . . 6 .  .  61   23  2
42603 426  . .  . . .  . . . . .  2 149  181  2
42603 426  . .  . . .  . . . . .  3  72  185  1
42603 426  . .  . . .  . . . . .  3 240  208  2
42603 426  . .  . . .  . . . . .  5 350  208  3
42603 426  . .  . . .  . . . . . 10 170  186  3
99901 999  . .  . . .  . 3 . . .  . 146    9  4
18002 180  . .  . . .  . . . . .  . 149    1  1
99901 999  . .  . . .  . . . . .  .  17   13  2
14803 148  . .  . . .  . . . . .  . 365    9 10
18002 180  . .  . . .  . . . . .  .  18   27  4
38403 384  . .  . . .  . . . . .  . 273    4  1
38403 384  . .  . . .  . . . . .  .  54    3  4
14803 148  . .  . . .  . . . . .  . 277   14  4
18002 180  . .  . . .  . . . . .  . 253    3  1
38403 384  . .  . . .  . . . . .  . 248   47  7
99901 999  . .  . . .  . . . . .  . 304   12  3
18002 180  . .  . . .  . . . . .  . 211   22  2
18002 180  . .  . . .  . . . . .  . 137   11  2
99901 999  . .  . . .  . . . . .  . 113   15  2
14803 148  . .  . . .  . . . . .  . 361    3  3
14803 148  . .  . . .  . . . . .  . 617   19  2
99901 999  . .  . . .  . . . . .  . 332    8  5
38403 384  . .  . . .  . . . . .  . 238   47  2
38403 384  . .  . . .  . . . . .  . 338    5  1
end
label values sample sample_lbl
label def sample_lbl 2401 "Angola 2015", modify
label def sample_lbl 10803 "Burundi 2016", modify
label def sample_lbl 12004 "Cameroon 2011", modify
label def sample_lbl 14803 "Chad 2014", modify
label def sample_lbl 18002 "Congo Democratic Republic 2013-14", modify
label def sample_lbl 23104 "Ethiopia 2016", modify
label def sample_lbl 28806 "Ghana 2014", modify
label def sample_lbl 32404 "Guinea 2018", modify
label def sample_lbl 38403 "Cote d'Ivoire 2011", modify
label def sample_lbl 42603 "Lesotho 2014", modify
label def sample_lbl 99901 "Gabon 2012", modify
label values country COUNTRY
label def COUNTRY 24 "angola", modify
label def COUNTRY 108 "burundi", modify
label def COUNTRY 120 "cameroon", modify
label def COUNTRY 148 "chad", modify
label def COUNTRY 180 "congo democratic republic", modify
label def COUNTRY 231 "ethiopia", modify
label def COUNTRY 288 "ghana", modify
label def COUNTRY 324 "guinea", modify
label def COUNTRY 384 "cote d'ivoire", modify
label def COUNTRY 426 "lesotho", modify
label def COUNTRY 999 "gabon", modify
label values geo_ao2015_2015 GEO_AO2015
label def GEO_AO2015 2 "zaire", modify
label def GEO_AO2015 9 "benguela", modify
label def GEO_AO2015 14 "namibe", modify
label def GEO_AO2015 18 "bengo", modify
label values geo_bi2010_2016 GEO_BI2010_2016
label def GEO_BI2010_2016 1 "bujumbura mairie", modify
label def GEO_BI2010_2016 3 "cankuzo, gitega, karusi, muramvya, ruyigi", modify
label def GEO_BI2010_2016 4 "bubanza, bujumbura rural,  bururi, cibitoke, makamba, mwaro, rutana, rumonge", modify
label values geo_ch2014_2014 MV024
label def MV024 19 "barh el gazal", modify
label values geo_cm2004_2011 GEO_CM2004_2011
label def GEO_CM2004_2011 5 "extrãªme-nord", modify
label def GEO_CM2004_2011 6 "littoral", modify
label def GEO_CM2004_2011 8 "nord-ouest", modify
label values geo_cg2014_2014 mv024
label values geo_gb2012_2012 mv024
label def mv024 3 "haut-ogoou�", modify
label values geo_et2000_2016 GEO_ET2000_2016
label def GEO_ET2000_2016 3 "amhara", modify
label def GEO_ET2000_2016 4 "oromia", modify
label def GEO_ET2000_2016 7 "southern nations, nationalities and peoples", modify
label def GEO_ET2000_2016 10 "addis ababa", modify
label values geo_gh1988_2014 GEO_GH1988_2014
label def GEO_GH1988_2014 3 "greater accra", modify
label def GEO_GH1988_2014 4 "volta", modify
label def GEO_GH1988_2014 6 "ashanti", modify
label def GEO_GH1988_2014 7 "brong-ahafo", modify
label values geo_gu2018_2018 MV101
label def MV101 1 "Boke", modify
label def MV101 3 "faranah", modify
label def MV101 5 "kindia", modify
label def MV101 6 "labe", modify
label values geo_ke1989_2014 GEO_KE1989_2014
label values geo_ls2004_2014 GEO_LS2004_2014
label def GEO_LS2004_2014 2 "leribe", modify
label def GEO_LS2004_2014 3 "berea", modify
label def GEO_LS2004_2014 5 "mafeteng", modify
label def GEO_LS2004_2014 10 "thaba tseka", modify
label values v003 LINENO
label def LINENO 1 "1", modify
label def LINENO 2 "2", modify
label def LINENO 3 "3", modify
label def LINENO 4 "4", modify
label def LINENO 5 "5", modify
label def LINENO 6 "6", modify
label def LINENO 7 "7", modify
label def LINENO 9 "9", modify
label def LINENO 10 "10", modify

Absorbing fixed effects using gsem

I am trying to run a poisson fixed effects model using gsem. Basically I want to duplicate the results from the following command after setting a panel data
Code:
xtpoisson dep_var ind_var, fe robust
The reason I want to use gsem is that I want to deal with endogeneity in my model and therefore need to run a structural model. I cannot explicitly add dummy variables for fixed effects as I have large number of fixed effects and Stata gets stuck trying to solve for the estimates. I need to absorb the estimates as the estimates themselves are not interesting in my analysis. I appreciate your response, any leads you can provide. Thanks

Absorbing fixed effects using gsem

I am trying to run a poisson fixed effects model using gsem. Basically I want to duplicate the results from the following command after setting a panel data
Code:
xtpoisson dep_var ind_var, fe robust
The reason I want to use gsem is that I want to deal with endogeneity in my model and therefore need to run a structural model. I cannot explicitly add dummy variables for fixed effects as I have large number of fixed effects and Stata gets stuck trying to solve for the estimates. I need to absorb the estimates as the estimates themselves are not interesting in my analysis. I appreciate your response, any leads you can provide. Thanks

Confidence intrevals and marginal effects significance for continuos variables in non-linear models

When using margins to evaluate the effect of a continuous variable in a non-linear model (e.g., logit, nbreg), it is common to look at the marginal effect over a range of values of such variable. On occasion, I find that the confidence interval (95) of the predicted marginal effect of a very low value of the variable in question overlaps with the confidence interval (95) of the predicted marginal effect of a very high value of the same variable. This is the case even though the coefficient of the variable in the model is highly significant (p-value .01) and has a confidence interval with a small range that is different than 0. So, if a plot the results with marginsplot, for example, I can see that the lower end of the CI for a high value of the variable overlaps with the higher end of the CI for a low value of the variable. Can I still interpret the statistically significant coefficient in the model as implying that low and high values of the continuous variable are different?

import delimited does not work..

Hello, I'm trying to import delimited a csv file, separated by commas. Please find a sample of 5 rows. I run

import delimited "asdf.csv", clear

OR

import delimited "asdf.csv", delimiter(",") clear

but Stata reads it in as if there is only one variable.. This is the first time I'm seeing this problem, and I'd greatly appreciate any and all comments. If you do list, it shows

+--------------------------------------------------------------------------------------------------------------------------------+
| v1 |
|--------------------------------------------------------------------------------------------------------------------------------|
1. | 33481,5,394539,637013,314748,,13433,BOBJ,12328X107 ,840,? ,2006-01-30 00:00:00,FR,4,0,1,-1,1.0,41.529701,100,4.50,.12,2006-0.. |
2. | 33481,5,394539,637013,314748,,13433,BOBJ,12328X107 ,840,? ,2006-01-30 00:00:00,FR,4,0,1,-1,1.0,41.529701,100,4.50,.12,2006-0.. |
3. | 33481,5,394539,637013,314748,,13433,BOBJ,12328X107 ,840,? ,2006-01-30 00:00:00,FR,4,0,1,-1,1.0,41.529701,100,4.50,.12,2006-0.. |
4. | 33481,5,394539,637013,314748,,1

so it certainly is delimited by commas.

Thanks so much for your time in advance!

Best,


John

How to choose model with different log likelihood values?

Dear friends,

Sorry for my stupid question! I am confused if the model is fitted better when respective (positive) log likelihood value is larger? But does it still applied if log likelihood value is negative? Thank you!

Rangestat for leave-out mean

----------------------- copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str2 podn float(ladn uw)
"AL" 137  .6530787
"AL" 133 .09962858
"AL" 133  .7349375
"AL" 137  .3416429
"AL" 137  .7651829
"B"  282  .9254544
"B"  282  .3284793
"B"  282   .601528
"B"  282 .05638361
"B"  282  .9922161
"B"  282  .7884781
"B"  282 .19412884
"B"  282 .05713714
"B"  282  .4019801
"B"  282 .10262794
"B"  286  .9294506
"B"  282  .7320663
"B"  282  .3816186
"B"  252  .8174805
"B"  282 .22413313
"B"  252   .489517
"B"  284  .8588205
"B"  285  .6861753
"B"  285  .4354155
"B"  285  .9446495
"B"  287  .4540383
"B"  282  .7198554
"B"  221  .6386167
"B"  282  .6791545
"B"  286 .26081806
"B"  286  .6180484
"B"  243 .58136946
"B"  254  .6579786
"BA"  22 .13102111
"BA" 209  .7721775
"BA"  54 .51663834
"BA"  54  .6716543
"BA"  54  .4881878
"BA"  22  .7893392
"BA" 211  .3827247
"BA" 211  .4432041
"BA" 209  .8036636
"BA" 209 .04741055
"BA" 211  .4632615
"BB"   8   .655027
"BB" 150 .32793915
"BB" 155 .23481174
"BB"   8  .2788624
"BB" 158  .6979516
"BB" 153  .4087807
"BB" 157  .5190807
"BB" 155  .8759601
"BB" 155  .1548233
"BD" 291  .2143494
"BD" 289  .9403666
"BD" 289  .8223539
"BD" 289 .11206491
"BD" 289  .3476477
"BD" 190 .06617011
"BD" 289  .8340919
"BD" 190  .5662497
"BD" 289  .8524801
"BD" 289    .79358
"BD" 289  .4145629
"BD" 289  .7217242
"BH"  28  .3480542
"BH"  29  .9046446
"BH"  91  .6097409
"BH"  91   .741581
"BH"  89  .3017222
"BH"  89  .4698355
"BH"  88  .7786833
"BH" 124  .6399533
"BH"  28  .3890726
"BH"  28 .40755025
"BL" 259 .04850375
"BL" 258  .3796008
"BL" 259 .07654884
"BL" 258  .9332509
"BL" 258  .9499664
"BL"   8 .19072783
"BL" 259 .21267034
"BN"  43 .15388475
"BN"  96  .7903761
"BN" 251  .7564719
"BN" 251  .6596532
"BN" 245  .4974095
"BN" 246  .6767726
"BN"  43 .05740402
"BN"  94 .15620527
"BN"  94   .741659
"BN"  94  .7825961
"BN"  98  .3825884
"BN"  98 .20780987
"BN"  43  .9423695
"BN" 245  .6629013
"BN"  96  .7783902
"BN"  96  .9061702
"BR" 299  .6617007
"BR" 299  .0472592
end
In my data ladn is nested within podn and I want to calculate the average of uw for each value of ladn across observations in that podn excluding those in that ladn. So, currently I am using code like this:

Code:
cap drop meanUW
gen meanUW=.
levelsof podn, local(pod)
foreach p of local pod {
    levelsof ladn if podn=="`p'" , local(ld)
    foreach l of local ld { 
        cap drop temp
        egen temp=mean(uw) if podn=="`p'" & ladn!=`l'
        replace meanUW=temp if podn=="`p'" & ladn!=`l'
        }
    }
But, as suggested in the manual for RANGESTAT this method is very slow indeed, and infeasibly so given that I have several million observations and will need to do this multiple times. I have tried to use RANGESTAT to do this, following the examples in the help files, but I think that because I want to exclude a group rather than an observation I am having problems. I tried this:

rangestat (mean) uw, interval(ladn 0 0) by(podn) excludeself

But, this doesn't give me the average by ladn but by observation. I would be grateful for any suggestions on how to use RANGESTAT or anything else to achieve a faster solution.

Best wishes,

Stu

renaming several variables in loop to reshape by category

i have several variables that i want to rename according to their category for example S2_Q1P- S2_Q7P would be plot and i want to rename them in a sequence such that the result is S2_Q1P_1- S2_Q7P_9.. I use the following code and i get the message

1 new variable name invalid
You attempted to rename S2_Q1K to 1. That is an invalid Stata variable name.



forval i=1/9 {
rename S2_Q1K `i' S2_Q1P `i' S2_Q1D `i'
rename S2_Q2AK`i' S2_Q2AP`i' S2_Q2AD`i'
rename S2_Q2BK`i' S2_Q2BP`i' S2_Q2BD`i'
rename S2_Q3AK`i' S2_Q3AP`i' S2_Q3AD`i'
rename S2_Q3BK `i' S2_Q3BP `i' S2_Q3BD `i'
rename S2_Q4K `i' S2_Q4P `i' S2_Q4D `i'
rename S2_Q5K `i' S2_Q5P `i' S2_Q5D `i'
rename S2_Q6K `i' S2_Q6P `i' S2_Q6D `i'
rename S2_Q7K `i' S2_Q7P `i' S2_Q7D `i'
}

i am renaming then in order to reshape such that corresponding questions align with the category name. should i use foreach v in varlist instead but how would i rename all of them in the simplest way possible? or is it not necessary for me to rename at all? I am very confused, earlier i had used forval i=1/9 to rename S2_Q2_01 and it had worked at that time. thank you for all the help i really appreciate it.

Small question on bar charts

I want to draw a hbar chart with three variables via the following command:
graph hbar incomep90 incomep95 incomep99, over(year) stacked

How do I filter the years that I don't want to draw? I have 28 years from 1989 to 2017 but I want to select three of them and draw only these years, all in the same chart.
Like: graph hbar incomep90 incomep95 incomep99, for (year==2000 year==2008 year==2015) stacked

So an if filter like graph hbar incomep90 incomep95 incomep99 if (year == XX) doesn't work for me because I want to select three years out of 29.

How do I do that?

Thanks a lot

PSA: I need an Econometrics tutor asap $30/hr

Somebody please help me study for a test ( undergrad ). I'm an adult, just went back to school during slow covid times. We can study via Zoom. I'm behind so please have at least a bachelors but hopefully you're close to having a PhD. DMs welcome! Serious only. Need someone right away. The class is called Intro to Econometrics. It's not just Stata, you should know the theory, terminology and be able to understand the formulas easily. Please be a native speaker, my professor has a thick accent and it's even harder to understand.

Convert Long String Order to Time Index

So this is a separate question following from my last post. It is in regards to the same variable "question_order", but now I am trying to convert the string's contents into a time index. So again my code is below:

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float ID byte _j strL question_order
1 1 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 2 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 3 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 4 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 5 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 6 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 7 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
1 8 "CountrysideDrawing2|GraffitiDrawing1|GraffitiDrawing2|StillLifeDrawing1|HouseDrawing2|HouseDrawing1|StillLifeDrawing2|CountrysideDrawing1"
2 1 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 2 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 3 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 4 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 5 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 6 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 7 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
2 8 "StillLifeDrawing2|GraffitiDrawing1|HouseDrawing2|HouseDrawing1|GraffitiDrawing2|StillLifeDrawing1|CountrysideDrawing2|CountrysideDrawing1"
end
ID refers to the participant, _j refers to the number of responses for each participant, and question_order refers to the order in which the _j responses were given over time. If _j = 1 then it references "GraffitiDrawing1", _j = 2 "GraffitiDrawing2", _j = 3 "HouseDrawing1", _j = 4 "HouseDrawing2", _j = 5 "CountrysideDrawing1", _j = 6 "CountrysideDrawing2", _j = 7 "StillLifeDrawing1", and _j = 8 "StillLifeDrawing2".

The question_order string structurally implies time_periods (very short time periods) that are separated with the pipe character "|". For example, the first question/response participant 1 received was "CountrysideDrawing2" or _j = 6; the second, "GraffitiDrawing1"; and so on... As you can see my data is also in 'long-format' hence where the _j variable comes from.

I am trying to find a clean way to produce a variable "t" for the time period that will capture the order in which they received the stimuli. I cannot think of a clean way of doing this, but I am also still learning STATA.

Any help would be great. Thanks in advance!