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

Numbering observations within groups if meeting certain criteria

$
0
0
Dear all,

I would like to number observations within groups, however considering only observations that meet certain criteria.

See example and data excerpt below.

"identifier" is the group variable within which the observations should be numbered. The variables "cf1" and "cf2" are binary with values 0 or 1. Based on this data I would like to generate variables "cf1_seq" and "cf2_seq" which number the observations of values of 1 in the variables "cf1" and "cf2" respectively. Whenever the value of "cf1" or "cf2" is 0, this observation should not be considered in the numbering and marked as missing in the variables "cf1_seq" and "cf2_seq".

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int identifier byte(cf1 cf2 cf1_seq cf2_seq)
1000 0 1 . 1
1000 1 1 1 2
1000 1 0 2 .
1000 0 0 . .
1001 1 0 1 .
1001 1 1 2 1
1001 1 0 3 .
 999 0 1 . 1
 999 0 1 . 2
 999 1 0 1 .
 999 0 1 . 3
 999 1 0 2 .
end

I am familiar with numbering observations by groups, e.g. with the following command
Code:
forval j = 1/2 {
bysort identifier: gen cf`j'_seq = [_n]
}
However, I am not sure how to number only those observations that meet certain criteria, such as taking a value of 1 in the example above.

I would very much appreciate your help, many thanks in advance!

Including variables that only apply to certain individuals

$
0
0
Hi,

I have the following example data

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double coder_id float n_passed_1 double adv_rate
 266705 1 .142857142857143
8357662 0                .
8383272 0                .
 286361 1                0
end

n_passed_1 is a dummy variable to indicate whether an individual participated in a tournament in the last semester. It is equal to 1 if they did participate and 0 if they didn't participate.
adv_rate is "advancement rate" - it shows how far through the individual got through the tournament before being eliminated. 0.142857... shows basically that the individual got to the second round in the tournament and was eliminated (they survived one round). 0 shows that the individual DID take part but only took part in the first round before getting eliminated (they survived 0 rounds). When the data is missing, it means that the individual simply didn't take part in the tournament (which is shown by the first dummy variable).

my dependent variable is how well an individual performs in singular weekly competitions. (One tournament runs every semester in parallel to these weekly competitions)

How can I include these variables in the right way in my regression to elicit the effect of participating in the last semester's tournament and the advancement rate (even though it doesn't apply to everyone) on performance in weekly singular competition?

Many thanks

Creating Table with more than two variables

$
0
0
Hi Everyone,


I want to create a table with a single variable X having two categories (YES NO) along the column side of the table. Along the row side, I have several variables each having multiple categories.

Child had diarrhoea
Yes No
Place of residence
Rural
Urban
Religion
Hindu
Muslim
Christian
Other
Wealth index
Rich
Middle
Poor
Total number of children ever born
1
2
3
4 or more


How can I create such a table in Stata?
The tab command only allows two-variables at time.

Any suggestions?

Label values differs for the merging variable

$
0
0
Dear all,

I want to create three group containing countries (1. nordic 2. EU 3. non-EU). In order to achive with this task. I need to first merge two datasets; a register data which contains country id (two letters) and lookup file which identifies the actuall country. When merging I get wrong matching. I ran " label list" for the merging variable (land_kod) and the label values differs, thus I assume it is due to the fact that the key variable "land_kod" in the two files do not have same values. Is there a smooth way to solve this problem? Further the second task: to create three groups, how can I make STATA to call all nordic countries in to the group (1.nordic) in a logical way?


use land
merge m:m land_kod using kon_fodd


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long lopnr int fodelsear long(kon land_kod)
1163681 1990 2 137
1077369 1991 2 137
1102192 1988 2 146
1060611 1991 2 137
1276382 1999 2 137
1080315 1996 1 125
end
label values kon kon
label def kon 1 "K", modify
label def kon 2 "M", modify
label values land_kod fodelseland
label def fodelseland 125 "PL", modify
label def fodelseland 137 "SE", modify
label def fodelseland 146 "SV", modify


The lookup file contains the following

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input long(from_datum tom_datum) byte aktuell long(land_kod land mis_mena mis_mena_kod)
9497 20453 1 1 198 12  2
9497 20453 1 2 173 11  1
9497 20453 1 3  52 14 15
9497 20453 1 4  60 14 15
9497 20453 1 5   6 15  8
9497 20453 1 6  11  7 11
end
format %tdD_m_Y from_datum
format %tdD_m_Y tom_datum
label values land_kod land_kod
label def land_kod 1 "00", modify
label def land_kod 2 "77", modify
label def land_kod 3 "88", modify
label def land_kod 4 "99", modify
label def land_kod 5 "AD", modify
label def land_kod 6 "AE", modify
label values land lan
label def lan 6 "ANDORRA", modify
label def lan 11 "ARABEMIRATEN, FÖRENADE", modify
label def lan 52 "EJ TILLÄMPLIG", modify
label def lan 60 "FELAKTIG", modify
label def lan 173 "Ospecificierad", modify
label def lan 198 "SAKNAS/OKÄND", modify
label values mis_mena mis_mena
label def mis_mena 7 "MENA + Turkiet", modify
label def mis_mena 11 "Saknas/okänd", modify
label def mis_mena 12 "Sverige", modify
label def mis_mena 14 "Övriga", modify
label def mis_mena 15 "Övriga Europa", modify
label values mis_mena_kod mis_mena_kod
label def mis_mena_kod 1 "00", modify
label def mis_mena_kod 2 "01", modify
label def mis_mena_kod 8 "04", modify
label def mis_mena_kod 11 "07", modify
label def mis_mena_kod 15 "99", modify




Running regression by group and year

$
0
0
I would like to run a regression by group and year on a weekly data basis. The regression equation looks as follows:
zi,t =αi +βi,yzm,t +εi,t ∀i,t∈y
Is there a Stata command which can run such a regression? Many thanks for your help.

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int date double(Zmt SMB HML RF) long stock float(return Zit) double _b_Zmt float z_excess double(v1 v0 reg_nobs reg_r2 reg_adj_r2 b_Zmt b_cons se_Zmt se_cons)
10962  -.23  1.26  -.86 .141 1          .          .                  . .467211                 .                  .  .                  .                  .                  .                    .                  .                  .
10969 -3.56   .52   .65 .141 1  -8.608311 -8.7493105 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  .                  .                  .                  .                    .                  .                  .
10976  -.47  -.37  -.31 .141 1  -.7245492  -.8655491 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  1                  .                  .                  .                    .                  .                  .
10983 -4.21   -.3    .9 .141 1 -4.3790236 -4.5200233 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  2                  .                  .                  .                    .                  .                  .
10990  1.22 -1.69   -.1 .142 1  4.5795636  4.4375634 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  3  .5562423445706656 .11248468914133114 1.4725446576905599   -.6670383357251168 1.3152532394733991  4.201858443708239
10997  1.06   .68  -.42 .142 1          0      -.142 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  4  .8176214921434165  .7264322382151247 1.9699237007057318   1.0328862029376782   .657877581452515 1.8638671560288946
11004  -.32   .05   .61 .142 1 -1.1398581  -1.281858 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  5  .7595976986432915  .6794635981910554 1.6886632991516553   .04502273821823666  .5484789033737867  1.413982442458092
11011 -2.48   .64  1.29 .142 1  -1.480652  -1.622652 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  6  .7554441220112734  .6943051525140918 1.6673056390605117  -.10841637418977879  .4743218192015768 1.1179816594570264
11018  3.16 -1.46  -.68 .161 1  1.5029048  1.3419048 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  7  .6994928473280394  .6393914167936473 1.5544165940892034    .1246942530227173 .45563616677322655 1.0821225352441541
11025   .77  1.03 -1.31 .161 1   9.261333   9.100333 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  8    .65428321595895  .5966637519521083 1.2413094063700665   -.5563240197478734  .3683678875413112  .9160165825722576
11032   .83   .08  -.89 .161 1   9.151989   8.990989 1.0846589648574492 .467211 .2062084003737894 .07916577681750825  9  .5059225115112344  .4353400131556965 1.4808113496641493    .5389696887809596  .5531032949433414 1.3044836949424323
11039 -1.41   .95  -.56 .161 1   4.966093   4.805093 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 10  .4800012413172828   .415001396481943 1.6615657446186558   1.3335660090009696  .6114381179279458 1.3774440140006607
11046   .51  -.42   .28 .161 1   -4.73114   -4.89214 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 11 .40598047445705865  .3399783049522873 1.5549600651131572   1.8097113047471711  .6269685726942935  1.372824316327695
11053  -.25  -.76 -1.13 .171 1  -.9320118 -1.1030118 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 12 .31108325136786025  .2421915765046463 1.4199983721067686   1.1300285426356882   .668240669340264 1.4043524557278175
11060  1.05  -.93 -1.12 .171 1    8.46351    8.29251 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 13   .306531232012606 .24348861674102484 1.4146186023986567    .9834326495473702  .6415331609572886 1.2960960747629622
11067 -2.69   .99   .26 .171 1  -6.935724  -7.106724 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 14  .3309548147789485  .2752010493438609  1.562276256880402   1.4426558091161565  .6412252011715216 1.2612521784139763
11074 -1.92   .45   .01 .171 1 -2.7960355 -2.9670355 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 15 .38602063918537866   .338791457584254 1.7290163831115892   1.2283430753562563  .6047822768673906  1.223595765610866
11081  2.48 -1.26  -.96 .169 1  2.2360559   2.067056 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 16  .3990096850025476  .3560818053598723  1.748978099085202    1.184480537503161  .5736703068968042  1.157038577311642
11088  3.46 -2.26  -.08 .169 1    6.56145    6.39245 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 17 .38198998907777093  .3407893216829556 1.6063573116462107    .9289853734824951  .5275556629443012 1.0799318121447334
11095   .86   .47  -.97 .169 1  -6.745263  -6.914263 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 18  .4247014810353481  .3887453236000573 1.6022304901222506    .9230985339494222 .46619728602653815  1.002345246007991
11102   .26  1.07 -1.57 .169 1  2.1727648  2.0037649 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 19  .3380082680675455 .29906757795387173 1.4965484024016644      .42745996597866  .5079593136762488  1.067720454967341
11109     2  -.88  -.52 .156 1   .6169435  .46094355 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 20  .3389730059415425   .302249284049406 1.5013960282227772    .4872200109678769 .49418100727356096 1.0128643315177843
11116    -1   .76   .91 .156 1  -6.135032  -6.291032 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 21 .32405357369896104 .28847744599890635 1.4331349026543756     .344116338415827   .474851706405162  .9721391408279789
11123   .86   .18 -1.65 .156 1   3.266185   3.110185 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 22  .3291629670258911  .2956211153771856 1.4898598092192987   .10933713110697302   .475590791823236   .956655125528706
11130 -1.94   .54  -.38 .156 1   5.064141   4.908141 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 23  .3343263736795816  .3026276295690855 1.5061614630054982     .183952141193978  .4637749001600706  .9161643196571707
11137   .46  -.01 -1.01 .156 1   7.833838   7.677838 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 24 .27135565391935357 .23823545637023336 1.3532359371131057    .4915180192528231  .4727706903308126  .9332427365135828
11144  -.05   -.5  -.71 .169 1          0      -.169 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 25 .26529458792652055 .23335087435810842 1.3890312694633355    .7558896740697539  .4819927756590511  .9332779205120371
11151  2.04  -.81 -1.61 .169 1  4.4667645  4.2977643 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 26  .2650188738074025 .23439466021604427  1.389024244188169    .7229878516189314 .47217598670497357  .8965272224231567
11158 -1.76  -.34    .5 .169 1 -12.298826 -12.467826 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 27  .2778281100961858 .24894123450003325 1.4042703245069041    .7500319187932928 .45280677006001574  .8622047230179269
11165 -2.48  -.08  1.19 .169 1   .9158382   .7468382 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 28 .29448317974014854  .2673479174224619  1.587665640556315   .37304581491625166 .48194314936563365  .9152942037070668
11172 -2.93 -2.59  1.52 .164 1  -.3036335  -.4676335 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 29 .27498896569987574 .24813670517024156  1.492379502958457    .5101422280656376  .4663500932517893  .8963841311263324
11179 -2.65   .33  -.47 .164 1  -6.060709  -6.224709 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 30 .26348118107138424 .23717693753821922 1.4117683187224757    .6059740311151873 .44606848311228064  .8761111301495651
11186 -2.59   -.9    .6 .164 1  -5.806916  -5.970916 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 31  .2872856759039854  .2627093199006746  1.472397293940918    .5241103901751323  .4306522980363926   .856952346916266
11193 -5.45 -2.41  2.01 .164 1  -2.447606  -2.611606 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 32  .3071393439294829  .2840439887271323 1.5200500885512973     .457721124516303  .4168237878490001  .8383823390797411
11200  3.55   .26 -1.57 .164 1  4.2261252   4.062125 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 33 .28843992922367356 .26548637855346946 1.3489256753313148    .5268688073300338 .38052681738608163  .8356916882374474
11207   .14  -.15   .03 .149 1 -1.6888587 -1.8378588 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 34  .2998500431644565  .2779703570133458 1.3191616748566903    .4781063804120133   .356341588443538  .8009252545327964
11214 -1.98   .22   .03 .149 1  -6.530972  -6.679972 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 35  .2958350318499711 .27449669948178845 1.3112928674687931    .4036354298297603 .35217225358398335  .7802087678230276
11221 -2.11 -1.09     1 .149 1  -7.351617  -7.500617 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 36 .30607617172478807 .28566664736375247 1.3524631361488542   .29663570756713536   .349242523758241  .7715526718628885
11228 -2.27  -2.8   -.3 .149 1  -7.934965  -8.083965 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 37 .31717145469097946  .2976620676821503 1.3995265432142048    .1853366979009321  .3471010317311253  .7659112410924686
11235  1.44 -1.67  -.05  .17 1  -3.450427  -3.620427 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 38 .32939922520654713  .3107714259067291  1.450417595657265   .07785709270563368  .3449153703575939   .761671931112994
11242 -4.11 -1.27  1.67  .17 1   .8946767   .7246767 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 39  .3060509364647615 .28729555636921444 1.3885424146327388  -.09966938517963475 .34373616628793624  .7534536008919221
11249  3.44  -2.4 -1.99  .17 1  11.059658  10.889658 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 40  .2729770728270678 .25384489053304315 1.2676235603003312 -.004344396865344269  .3355903556397007   .758378146205359
11256 -2.13   .93  -.25  .17 1 -4.3825407  -4.552541 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 41  .3182671997340143 .30078687152206596 1.3906969410072683   .21216034685015456   .325920253332771  .7482629469654478
11263  1.86 -2.64   .55 .141 1   5.835962   5.694963 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 42  .3246614705246674 .30777800728778404 1.4046549150524787    .1762787675386942  .3203207227557372  .7341870955078593
11270   .87  -.13  -.33 .141 1  11.808538   11.66754 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 43 .33800727915806955 .32186111523509553 1.4358025836337063    .2578482343362075  .3138097136416844  .7164021194495169
11277  1.41  1.04  -.54 .141 1   -.717422   -.858422 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 44  .3338229052257751  .3179615458263888 1.4961244913529814    .5140500102255076  .3261218287785852  .7372425736096561
11284  -.73   .52  -.65 .141 1   3.557749   3.416749 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 45  .3260528276301097 .31037963757499587 1.4678701163705872    .4259793539962173 .32182690117805907  .7225774855505802
11291  2.24    .2 -1.33 .141 1  1.0295126   .8885127 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 46 .32071275722777776 .30527441080113626 1.4615348537004347    .5118445888853541  .3206649185963889  .7129357355203958
11298  1.98   .97   -.1 .149 1  15.647645  15.498645 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 47 .31568953992579935  .3004826408130393 1.4287711984570146   .43938369697985613 .31358329795042145  .6973029387761304
11305  -.36   -.2  -.76 .149 1  -6.174531  -6.323532 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 48 .32650792601301454  .3118667939698192 1.5477643080179306    .7277474649449904  .3277519558554112  .7272349268492915
11312  1.22 -1.08   .02 .149 1  12.852174  12.703174 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 49  .3193913453775639  .3049103101728312 1.5498961677314598    .5958198916450821  .3300204386592198  .7249564286206538
11319  -.84   .28  -.14 .149 1 -4.4444447  -4.593445 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 50 .32132534827612846 .30718629303188116 1.6140358555294467     .816415324892905  .3385718764370938  .7385800951747762
11326 -2.04  1.76  1.76 .129 1    .580589    .451589 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 51  .3216094832909926 .30776477886835973 1.6239511963069284    .7395522930663292 .33693831095774135  .7288531252640771
11333 -1.93     0  -.35 .129 1  8.6713915   8.542392 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .31702115572509854  .3033615788396006  1.601840465040345    .7911071807047121  .3325016168536086  .7184902888332286
11340  4.68 -3.28 -1.92 .129 1   6.914156   6.785156 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2602193193503835 .24542370573739114 1.4686224902461482    1.037741333081806 .35019254540346856  .7426424363363143
11347   1.7  3.32  -.81 .129 1   6.467016   6.338016 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2734631033214002 .25893236538782827 1.4456989588475164    1.035549611732657  .3332516699501243  .7387512662862565
11354   2.7  3.76  -.75 .119 1  4.2050138   4.086014 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2697116963916705  .2551059303195039  1.475625074464447     1.08170050565865 .34339052392441505  .7388019237316314
11361  4.69  -.47  -.26 .119 1    7.39893    7.27993 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2697082019081023 .25510236594626434 1.4569156850105993   1.0324412597558623  .3390396971606899  .7381795510654438
11368  2.66  1.05   .02 .119 1  -3.555792  -3.674792 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .28704964519587883  .2727906380997964 1.4570812809787472   1.0734596299065957 .32475056419232146  .7363951427052945
11375  -.74  1.14 -1.09 .119 1  3.6868906   3.567891 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2590818473251956 .24426348427169953 1.3735669541746316    .9523232523191522 .32849703710989414  .7545413742714099
11382  1.36   .69   .36  .11 1  -3.347309  -3.457309 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .25223864354370285 .23728341641457684 1.3698312698648147   1.0066797223427997  .3335475625402904  .7582787431580746
11389  1.56  2.77 -1.29  .11 1  12.553926  12.443926 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .2482120787272021 .23317632030174607  1.386156395174666     .960184426836791  .3411641957148793  .7637639334444568
11396  -.72 -1.12    .9  .11 1   1.922831   1.812831 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .25399079387105167 .23907060974847272 1.4199183620018192     .999562222777719  .3441450117016319  .7731530884780345
11403  -1.3  1.53  -.05  .11 1 -4.5273166 -4.6373167 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .25276985628790816 .23782525341366634 1.3948899765284926    .9059630071855562  .3391716172393198  .7617323585377661
11410  2.23   .78  -.61  .11 1   7.507987   7.397987 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .26999159971886966  .2553914317132471 1.4482251254015226    .7168016723576041  .3367750260596929  .7559200063122447
11417   .52  1.67  -.83 .133 1  2.0232449   1.890245 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .28756032715847174  .2733115337016411 1.4849251259945553    .9008504912259099 .33054387720874034  .7485771939114154
11424  1.06  -.09   .22 .133 1   3.423578   3.290578 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .28738358349835974  .2731312551683269 1.4828789117266963     .936700257398548  .3302308332917132  .7481596869239909
11431    .8  -.49  1.17 .133 1 -16.898474 -17.031473 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .28740760738690135 .27315575953463944 1.4656465573662518    .8425471441139902 .32637411805253663  .7394512714055635
11438 -1.53   .14   .06 .133 1  -1.678312  -1.811312 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .21784974311633948 .20220673797866628  1.376655709109219    .5712884527120858 .36889851591127537  .8254054752847757
11445   .28  -.58   .31 .118 1  -16.41798  -16.53598 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .21555624091526973  .1998673657335751 1.3711025792588576    .5843519417369932   .369901038898902   .825507010136104
11452 -1.04  1.22  -.26 .118 1   4.592961   4.474961 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .18924516577532047 .17303006909082685  1.380882646586374    .2829750325842228  .4042072938406426  .8914307713773894
11459 -1.23 -1.09    .6 .118 1  -8.293724  -8.411724 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .17158208732034846 .15501372906675537 1.3361680855529146   .36920266467172347 .41520718415688707  .8957587493969181
11466  1.45  -.21  -.63 .118 1 -2.1291633 -2.2471633 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .18789055704631663 .17164836818724294  1.402002592331469   .39145031837245536 .41221008954010846  .8907124664536424
11473     3  -.43   .19 .118 1   2.452308   2.334308 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .18169630991495106 .16533023611325015 1.3745169149576755   .27935640741393397 .41252406410690134  .8951185410879016
11480 -2.21  1.82  1.27 .104 1 -1.8620224 -1.9660224 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .18382755018590033 .16750410118961834 1.3700593486409123   .28931737671550395  .4082630201770764  .8948727316924955
11487   .33 -1.29  -.28 .104 1 -10.839443 -10.943443 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .18190006214016868 .16553806338297206  1.341377168336461     .406069739585657 .40230243745854183  .8886359789995926
11494 -1.33  -.21   .35 .104 1  2.1280167  2.0240166 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1685707094370112 .15194212362575144 1.3233087634778098    .1503654297190465  .4156212931433285  .9169138824754637
11501 -1.79  -.26  -.04 .104 1 -1.1897328 -1.2937328 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .17829062105788934  .1618564334790472 1.3615796025678293   .07705237751353264  .4133832807891307   .908375527338453
11508   .64 -1.04  -.65 .122 1   9.938467   9.816467 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1791901046527299  .1627739067457845 1.3418453875150669  -.03621797574655257 .40614560284290047  .8977738433001429
11515  1.74   .38  -.75 .122 1   2.465737   2.343737 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1786300933682586  .1622026952356238 1.3633595458072492    .1373430110662348  .4134447504857537  .9146402682049697
11522   .99    .5   .81 .122 1 -1.6032833 -1.7252833 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .17552346739506183 .15903393674296307  1.351266427847809   .10793342458099534 .41416895214068095  .9141987164473281
11529  -.99  -.34   .51 .122 1 -2.4456115 -2.5676115 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .16208304331300216 .14532470417926224 1.2650477249417142   .24977468793987573 .40677439339302895  .8941166162688391
11536   1.7  -.03 -1.42 .115 1  11.421102  11.306102 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .16956488153683003 .15295617916756665 1.3103331899062614    .1449621445937729  .4100923212359633  .8920862167745041
11543   .17   .28  -.01 .115 1  1.4990475  1.3840475 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1817557405877646  .1653908553995198 1.4090192719792134    .2354093592256457   .422794516828445  .9090125601304525
11550   -.2   .54   .65 .115 1   4.925746   4.810747 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .16992142327497348  .1533198517404729  1.374352214488602    .3139794899023825 .42958447577993775  .9100756926812285
11557  1.85  -.57  -.48 .115 1 -.23329963  -.3482996 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1549789698415717 .13807854923840313 1.3283033802175999     .471771647968522  .4386414307860141  .9158912095860582
11564   .48   .96  -.69 .115 1          0      -.115 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .15521888418058288 .13832326186419452 1.4323680489666788   .28343520368566366  .4725735850993058  .9277902070690875
11571  -1.7   .58   .15 .114 1  -2.829527  -2.943527 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .15235566018292532  .1354027733865838 1.4546899339085182    .2792527525037102 .48524712164193895  .9228004125466511
11578 -1.27   .92  -.54 .114 1  -5.583186  -5.697186 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .15668340472411488 .13981707281859723 1.4604389027916151   .30749894700751057  .4791618291876259  .9181557906118267
11585   1.3   .19 -1.05 .114 1  4.1149817   4.000982 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .15188308385231206  .1349207455293583  1.444948743948617    .3119630280880542  .4828815355682323  .9196750600099707
11592  -.45  -.19   .44 .114 1  -3.212469  -3.326469 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .13896382375808145 .12174310023324308 1.3857039510985543    .4633321075806415  .4878039071587997  .9222225797580715
11599 -1.06   .48  -.01 .106 1  -1.528863  -1.634863 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .12397542259303887 .10645493104489956 1.3160001867699753    .5381050148840409  .4947220818226894  .9227617629724024
11606  -.28  -.51   .08 .106 1    .516582    .410582 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52   .134024668977042 .11670516235658279  1.359139007676395    .6219625207950472 .48858402558905595  .9089170632719362
11613  2.99   .51  -.28 .106 1  13.404696  13.298697 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .14999757920742568 .13299753079157428 1.5311677954493839    .4329779456430751  .5154727839359768   .913042973751249
11620 -2.19   .33   .23 .106 1   -6.82023   -6.92623 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .15135437920633144 .13438146679045804 1.5679246180453505    .4751743645665092   .525056293645824    .92173381284318
11627  2.07   .38  -.77 .098 1    -.48635    -.58435 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1576460519318204 .14079897297045674 1.6093441728600186   .41179675198938714  .5261016794037154  .9243155966444677
11634    .6   .14   -.1 .098 1  4.4120426  4.3140426 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .14642756966556275 .12935612105887406 1.5420251943708374    .3165697666067875  .5265204330978012  .9274264332412231
11641 -2.55   .13    .2 .098 1   -6.10308   -6.20108 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52  .1480381462705899 .13099890919600166 1.5179302680479645    .1945015661245626  .5149796582041829   .905981765618041
11648 -1.74  -.47 -1.29 .098 1   2.734859   2.636859 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .16679140784137758  .1501272359982051 1.5857805622948713   .18059265193941065  .5012427692391268  .8940971091212436
11655  -.25  -.42  -.53 .098 1   -.975819  -1.073819 1.0846589648574492 .467211 .2062084003737894 .07916577681750825 52 .16234164503869025 .14558847793946406 1.5473351597925264   .21081252994496358 .49707037801937876  .8933140127976661
end
format %tdnn/dd/CCYY date
label values stock stock1
label def stock1 1 "RKML", modify

Matching between variable names and values

$
0
0
Dear all,

I have a dataset of workers (worker_id) employed at firms (firm_id), the firms are allocated to one out of 7 industries and the variables "share_VS_7_*" indicate how much prior experience a worker has in each industry.

I would now like to generate a new variable "firm_industry_exp" which takes the values from the relevant variable "share_VS_7_*". Hence, I am looking for a way to identify the correct "share_VS_7_*" variable based on the value of the variable "industry" in each row, i.e. a way to match parts of the variable name and value.

For example, in line 1 below, the industry is 1 ("Business and Financial Services"). Hence, the worker's experience in this particular industry is given by the variable "share_VS_7_1" and the new variable should therefore take the same values as this variable.

I would really appreciate your guidance on how to implement this dynamically, please see the data structure in the excerpt below. Many thanks in advance for your help!

Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input int(worker_id firm_id) long industry_VS_7 float(share_VS_7_1 share_VS_7_2 share_VS_7_3 share_VS_7_4 share_VS_7_5 share_VS_7_6 share_VS_7_7)
132   11 1      .25    0        .5 0   0    0       .25
132 1585 3        0    0         1 0   0    0         0
132 1131 3        0    0         1 0   0    0         0
512 4364 5        0 .125         0 0 .75 .125         0
132  155 7 .3333333    0 .44444445 0   0    0 .22222222
end
label values industry_VS_7 industry_VS_7
label def industry_VS_7 1 "Business and Financial Services", modify
label def industry_VS_7 3 "Consumer Services Group", modify
label def industry_VS_7 5 "Healthcare", modify
label def industry_VS_7 7 "Information Technology", modify

Difference-in-difference question

$
0
0
Forgive me if this isn't allowed as it's more statistical than STATA.

I am conducting a DiD regression using SOEP data. It involves the effect of a reform on marital stability of men who become fathers.

So the three groups are men who never become parents, parents who had a child before the reform and parents who had a child after the reform.

The model is
Y= Parent + ReformYear + Parent*ReformYear + X + e

my concern is the dependant variable is Divorce (dummy variable =1 if divorced before time t) measured 10 years after the reform so there is no variation of the dependant variable within fathers.

e.g. if father i has a child in 2007, he is measured in 2006 (pre reform) and 2007 (post reform), but the dependant variable Divorce is measured in 2017 so both observations will have the same value for divorce.

Is this an issue?

Exporting graphs in another format

$
0
0
Hi, I would like to export a graph for publication with required size 85mm, 300dpi, in tiff-format with LZW compression? I can save the graph as tiff file, and the size is then 2.13MB, but the resolution is only 96x96 dpi. Is it possible to do it directly from Stata, without using another program? Or should I try exporting it in another format to get enough resolution for the journal's requirements?
I use Stata14 with Windows 10. Thanks, Charlotta

Linearity

$
0
0
've drawn the ACPR plot in order to verify the presence of linearity in my model. Can you help me with the interpretation of the results? What the two lines represent is not clear to me, nor is the way dots should arrange themselves in order to verify the assumption of linearity.
I've alleged one of the graph I'm trying to interpret. Thank you

How to assign different axis in a panel graph?

$
0
0

Hi,
I have a panel data set. I want to draw a panel graph for individual countries. When I use the following code

Code:
 twoway (line fdi_inflows year), by(country_name)
It is able to draw the panel graph for all countries. However, since Singapore has very higher FDI inflows it dwarfs the variation in FDI inflows of other countries. Thus, I want a panel graph that will use the primary axis for all countries except Singapore and the secondary-axis for Singapore. The data is supplied below.

Code:
clear all
input str20 country_name int year float fdi_inflows
Indonesia 2005 2.91611
Indonesia 2006 1.34794
Indonesia 2007 1.60301
Indonesia 2008 1.82633
Indonesia 2009 .903919
Indonesia 2010 2.02518
Indonesia 2011 2.30298
Indonesia 2012 2.30978
Indonesia 2013 2.55136
Indonesia 2014 2.81997
Indonesia 2015 2.29762
Indonesia 2016 .487372
Indonesia 2017 2.01988
Malaysia 2005 2.73439
Malaysia 2006 4.72719
Malaysia 2007 4.68689
Malaysia 2008 3.28079
Malaysia 2009 .056692
Malaysia 2010 4.26859
Malaysia 2011 5.07443
Malaysia 2012 2.82906
Malaysia 2013 3.4943
Malaysia 2014 3.14127
Malaysia 2015 3.27095
Malaysia 2016 4.47132
Malaysia 2017 2.93721
Singapore 2005 14.1543
Singapore 2006 24.8428
Singapore 2007 26.3804
Singapore 2008 6.30163
Singapore 2009 12.2693
Singapore 2010 22.9665
Singapore 2011 17.5964
Singapore 2012 18.7439
Singapore 2013 20.9345
Singapore 2014 21.8193
Singapore 2015 22.6538
Singapore 2016 23.1248
Singapore 2017 28.0169
end
Any help will be greatly appreciated.
Thank you.

Exporting to pdf from marginsplot labels disappear

$
0
0
I'm running Stata/SE 15.1 for Mac.

When I export from marginsplot to pdf the titles, labels and tick-marks are blank in the pdf file

regress price mpg
margins, at(mpg=(12(1)42)) atmeans post
marginsplot ,title ("") ytitle("Price") ///
xtitle("MPG", margin(l-10)) ///
ysc (r(0 .6)) ylabel (#5) graphregion(margin(l+5 r+10)) bgcolor(white) noci ///
xla(1 "12" 9 `" "20" "median" "' 15 `" "26" "75th pctl" "' ) ///
plot1opts(msymbol(none) lpattern("--") lcolor(navy))
graph save "$DESK/auto.gph", replace
graph export "$DESK/auto.pdf", replace

Generate new variable using groups of countries

$
0
0
Hello,

I have a variable ("gdppcgrowth") that is the GDP per capita growth (weighted average per countries include in a group).There are for groups of countries in my sample (Scandinavian, continental, mediterranean and anglo-saxon). I want to generate a new variable that is the difference between the GDP per capital growth of the countries included in the Scandinavian groups and the GDP per capital growth of the countries included in the mediterranean group. Can you help me with the code?
I send an example of the dataset:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input str52 country int year float(groups mean_gdppcgrowth)
"Austria"        1995 2 2.3407316
"Ireland"        1995 3   6.18587
"Spain"          1995 4 2.2713282
"Greece"         1995 4 2.2713282
"Belgium"        1995 2 2.3407316
"Denmark"        1995 1  2.492248
"United Kingdom" 1995 3   6.18587
"Italy"          1995 4 2.2713282
"Ireland"        1996 3  6.567645
"Luxembourg"     1997 2    3.7762
"Austria"        1997 2    3.7762
"Slovenia"       1997 2    3.7762
"Belgium"        1997 2    3.7762
"Italy"          1998 4 1.7813244
"Netherlands"    1999 1  4.337374
"United Kingdom" 1999 3  3.083962
"Slovenia"       1999 2 4.3104277
"Hungary"        1999 2 4.3104277
"Finland"        2000 1  4.553648
"Belgium"        2000 2 4.4625287
"Ireland"        2000 3  7.996473
"Luxembourg"     2000 2 4.4625287
"Spain"          2000 4 4.0039873
"Italy"          2000 4 4.0039873
"Denmark"        2000 1  4.553648
"Sweden"         2000 1  4.553648
"Greece"         2000 4 4.0039873
"Austria"        2000 2 4.4625287
"Italy"          2003 4 1.2678407
"Belgium"        2003 2  .3949078
"Ireland"        2003 3 1.3554184
"Spain"          2003 4 1.2678407
"Portugal"       2003 4 1.2678407
"France"         2003 2  .3949078
"Denmark"        2003 1  1.247661
"Austria"        2003 2  .3949078
"Luxembourg"     2003 2  .3949078
"Sweden"         2003 1  1.247661
"Finland"        2003 1  1.247661
"Greece"         2003 4 1.2678407
"Belgium"        2004 2 3.4276695
"Finland"        2004 1   2.91047
"Portugal"       2004 4 2.1187565
"Hungary"        2004 2 3.4276695
"France"         2004 2 3.4276695
"United Kingdom" 2004 3  3.290518
"Austria"        2004 2 3.4276695
"Italy"          2004 4 2.1187565
"Poland"         2004 2 3.4276695
"Ireland"        2004 3  3.290518
"Greece"         2004 4 2.1187565
"Sweden"         2004 1   2.91047
"Spain"          2004 4 2.1187565
"Denmark"        2004 1   2.91047
"Netherlands"    2004 1   2.91047
"Slovenia"       2004 2 3.4276695
"Luxembourg"     2004 2 3.4276695
"Denmark"        2005 1 2.1953652
"Portugal"       2005 4  .7847396
"Finland"        2005 1 2.1953652
"United Kingdom" 2005 3  2.947908
"Belgium"        2005 2   2.48923
"Greece"         2005 4  .7847396
"Luxembourg"     2005 2   2.48923
"Hungary"        2005 2   2.48923
"France"         2005 2   2.48923
"Spain"          2005 4  .7847396
"Poland"         2005 2   2.48923
"Sweden"         2005 1 2.1953652
"Austria"        2005 2   2.48923
"Ireland"        2005 3  2.947908
"Netherlands"    2005 1 2.1953652
"Italy"          2005 4  .7847396
"Slovenia"       2005 2   2.48923
"Slovenia"       2006 2  3.703262
"Finland"        2006 1  3.627941
"Greece"         2006 4  2.655127
"Portugal"       2006 4  2.655127
"Sweden"         2006 1  3.627941
"Poland"         2006 2  3.703262
"Spain"          2006 4  2.655127
"Italy"          2006 4  2.655127
"Netherlands"    2006 1  3.627941
"France"         2006 2  3.703262
"Belgium"        2006 2  3.703262
"United Kingdom" 2006 3 2.1557891
"Denmark"        2006 1  3.627941
"Austria"        2006 2  3.703262
"Ireland"        2006 3 2.1557891
"Hungary"        2006 2  3.703262
"Luxembourg"     2006 2  3.703262
"Denmark"        2007 1    2.8822
"Netherlands"    2007 1    2.8822
"Spain"          2007 4  1.999245
"France"         2007 2  4.095892
"Hungary"        2007 2  4.095892
"Greece"         2007 4  1.999245
"Luxembourg"     2007 2  4.095892
"Finland"        2007 1    2.8822
"Ireland"        2007 3 1.9795177
end
format %ty year
label values groups gnames
label def gnames 1 "Scandinavian", modify
label def gnames 2 "Continental", modify
label def gnames 3 "Anglo_Saxon", modify
label def gnames 4 "Mediterranean", modify
Thank you in advance.

How to use a Loop to Generate Duplicate Variable for a Subset of Panel Data (PSID)?

$
0
0
I am using panel data, particularly the Panel Study of Income Dynamics (PSID). Each variable has a very different name each year. I am trying to generate variable names that are consistent. For example, age1968, age1969....age2003. In other words, I am trying to duplicate the original variables with consistent naming.

However, I am trying to do this conditional on each observation's value on another variable. In other words, I want to duplicate the values for only a subset of the variables. For example, gen age1969 = V1008 if ER30022 == 1 & ER30021 == 1. However, as there are a lot of variables and years, I'd rather not run hundreds of lines of code to do this for each individual variable. I'd rather do this through some loop. Below is the loop I tried.


Code:

*Years
local tvars 1969 1970 1971 1972 1973 1974 1975 1976 1977 ///
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ///
1991 1992 1993 1994 1995 1996 1997 1999 2001 2003

*AGE 1969-2003
local avars V1008 V1239 V1942 V2542 V3095 V3508 ///
V3921 V4436 V5350 V5850 V6462 V7067 V7658 V8352 ///
V8961 V10419 V11606 V13011 V14114 V15130 V16631 V18049 ///
V19349 V20651 V22406 ER2007 ER5006 ER7006 ER10009 ER13010 ER17013 ER21017

*Trying to create the variables for each age-year pair
forval i = 1/32 {
    local temp : word `i' of `tvars'
    local a : word `i' of `avars'
    gen age`temp' = `a' if ER30022 == 1 & ER30021 == 1
}

The first variable that should be created in age1969 which should equal V1008 conditional on variables ER30022 == 1 & ER30021 == 1. However, the error I get says that "
variable age1969 already defined"

What am I doing wrong here? Any guidance?

Svyset melogit and weights

$
0
0
Hello,

I have three household surveys for Vietnam, Nepal, and Zambia. I would like to run a multilevel logistic regression using all three datasets to find out how significant different household socio-economic characteristics are for achieving wellbeing when all countries are considered (in between countries).

Here are my questions:

1) I'm not sure if I'm setting correctly svyset for the melogit calculation. The strata level supposed to be a country (country_id) and the psu is each individual household (id_hh). I have weights for households and individuals and I use the latter one for the analysis. I set weight for country_id to be 1 (I generated a separate variable for that)

Code:
gen one=1
svyset id_hh , weight(one)  strata( country_id ) ||  _n, weight( wt_ind )
svy:melogit achieved_all  rural not_poor Bicycle Motor_cycle car_all_type  inc_cap_oecd_doll indirect clean_fuels tot_resid_fuels share_dirty_fuels F2 F8 F7 F9  F11, or
2) I also wonder if I can run melogit without svy by applying weights directly within melogit function. I have not figured out the command for this. If I type the command below, STATA is taking to long to calculate and do not spit out any results. This would be my preferable option - to use only melogit without svyset.

Code:
melogit achieved_all  rural not_poor Bicycle Motor_cycle car_all_type  inc_cap_oecd_doll indirect clean_fuels tot_resid_fuels share_dirty_fuels F2 F8 F7 F9  F11 [weight=wt_ind] || country_id:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float country_id double id_hh float wt_ind double wt_hh float(achieved_all rural not_poor Bicycle Motor_cycle car_all_type inc_cap_oecd_doll indirect clean_fuels tot_resid_fuels share_dirty_fuels F2 F8 F7 F9 F11 one)
3  1 3431.5095  1143.836528422721 1 0 1 0 0 0  2135.837  2.932259  2.418551  2.418551         0 .48979065  .9228074  .22896788 1.0457374  .7038306 1
2  1     23862               3977 1 0 1 0 1 1  2502.056  15.66765 13.819222 13.819222         0  .9959788 1.1579261  1.0312163  1.141407 1.0568452 1
3  2  829.5112    276.50371902091 0 1 1 1 0 0  72.09024 .22780228         0 14.453397       100         0 .03939118 .036324713 .07559729         0 1
3  3  878.5577 125.50824756830845 0 0 1 0 0 0 16.888107  3.421303  5.182552   50.7836  89.79483 .48979065  .9621986   .8609523 1.0457374  .9715392 1
2  3     15908               3977 1 0 1 1 1 0  5904.989  22.74347  8.978337  8.978337         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2  4     19220               4805 1 0 1 1 1 0  3168.067 14.845183  9.852883  9.852883         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3  4 2113.1077  234.7897367648935 0 1 1 1 0 0 1193.3346 4.0565367         0 4.4334917       100         0  .4446395 .036324713  .4331836  .6647144 1
3  5  509.9308 169.97693344836043 0 1 0 0 0 0 149.27893  .5390625         0    5.3201       100         0         0          0  .1276337         0 1
3  6  2996.046  374.5057278207885 0 1 1 0 0 0 288.61533  .8184853         0  8.977729       100         0 .03939118 .036324713 .17424257         0 1
2  6     24025               4805 1 0 1 0 1 0 3283.9814 16.534048  7.882306  7.882306         0  .9959788  .9016707  1.0312163  1.141407  .7046468 1
3  7  409.7897  37.25360992839712 0 1 0 1 0 0 156.96233  .9758744         0  7.463776       100         0 .03939118          0  .4509521         0 1
2  7      8280               4140 1 0 1 0 1 0 4751.7476  41.35414 13.364527 13.364527         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2  8     12420               4140 1 0 1 0 1 0  4960.745 23.561584  7.677613  7.677613         0  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
3  8 602.64417 150.66103869807938 0 1 1 0 0 0  548.5766 1.1090566         0  .3990175       100         0         0 .036324713 .13342607         0 1
3  9 1519.3517 151.93516893205108 0 0 1 1 0 0 1776.0364  1.625633 1.4510887  6.239113  76.74207         0  .4840307   .2713815  .2085105  .6647144 1
2  9     16560               4140 1 0 1 0 1 0  4669.726  26.67707  7.357579  7.357579         0  .9959788  .7491654  1.0871737  1.141407 1.0568452 1
2 10     22355               4471 1 0 1 0 1 0 4160.8613 17.138271  9.810104  9.810104         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 10 2253.0984  563.2745821173644 0 1 1 0 0 0 2219.7942 4.6156397         0   9.97545       100         0  .4840307  .22896788  .1854625         0 1
3 11  898.8867 179.77733620545214 1 0 1 1 0 0  3.743456 1.8173698 1.4511133 1.4511133         0         0  .9621986 .036324713  .7459798  .6647144 1
2 11     17884               4471 1 0 1 1 1 0  3661.307 17.257813  5.706996  5.706996         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2 12     17884               4471 1 0 1 0 1 0  3181.666 22.981884  7.208337  7.208337         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 12 198.95908 22.106563891903196 0 1 1 1 0 0  860.1058  .9955037         0  10.63874       100         0 .03939118          0 .07559729         0 1
2 13     15280               3820 1 0 1 0 1 0 4753.1567  22.88666  4.521252  4.521252         0  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
3 13  176.3642 44.091054336715615 0 1 0 0 0 0  451.7607  .8523216         0  7.778911       100         0 .03939118 .036324713 .28410777         0 1
3 14 1214.1974  303.5493398554946 0 1 1 1 0 0 144.98337  .8948803         0  5.985209       100         0         0 .036324713  .1098652         0 1
2 14     22920               3820 1 0 1 1 1 0  3309.476 14.963904  6.255684  6.255684         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2 15     22920               3820 1 0 1 1 1 0  3133.355  14.85294  3.924042  3.924042         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 15  411.8732 205.93658900110267 0 1 0 0 0 0 418.68765 1.0939922         0 19.950407       100         0         0 .036324713  .1854625         0 1
2 16     15988               3997 1 0 1 1 1 0 2817.2334 22.632874  5.601757  8.777926 36.183598  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 16    929.77 154.96166252719183 0 0 0 0 0 0 1002.1522 2.0344088  2.418584  9.068901  73.33101         0  .4840307 .036324713 .15647407         0 1
3 17 147.33421 29.466841201520634 0 0 1 0 0 0  402.4436  2.390262         0  14.36299       100         0 .03939118   .2713815 1.1213347         0 1
3 18  4575.346  1143.836528422721 0 0 1 0 0 0  629.6224  3.757969         0  19.95068       100         0 .03939118  .22896788  .2085105  .6647144 1
2 19     16352               4088 1 0 1 0 1 0  2805.358  13.12494 4.6777043 4.6777043         0  .9959788  .7491654  1.0312163  1.141407 1.0568452 1
3 19  393.1438  32.76197982298128 1 0 1 0 1 1 3991.7156  3.880407  2.418704  2.418704         0         0  .5175591  1.0172708  .8210642  .9715392 1
2 20      8176               4088 1 0 1 1 0 0 1886.6094 11.821956  5.936051  5.936051         0  .4979894  .7491654  1.0871737  1.141407 1.0568452 1
3 20 1061.0646  265.2661347184559 0 1 1 1 0 0  414.0243 1.5282116         0  7.980179       100         0  .4840307 .036324713 .07559729         0 1
2 21     16352               4088 1 0 1 0 1 0 1826.9886 10.843216 3.4265676 3.4265676         0  .4979894  .7491654  1.0312163  1.141407 1.0568452 1
3 21 1375.4097 152.82329796274607 0 1 0 1 0 0 461.47855 1.9204497         0  5.320312       100         0 .03939118 .036324713 .05203642         0 1
3 22 144.25308  72.12654266846475 0 1 1 0 0 0  414.2789  2.210518         0  9.575895       100         0 .03939118 .036324713 .28410777         0 1
2 22      7142               3571 1 0 1 0 1 0 4184.6377 16.819134  24.56804  24.56804         0  .9959788  .7491654  1.0871737  1.141407 1.0568452 1
2 23     14284               3571 1 0 1 0 1 0 1895.2163 12.782938  9.383526  9.383526         0  .9959788  .7491654  1.0312163  1.141407 1.0568452 1
3 23  310.8699  155.4349392014762 1 0 1 0 0 0  3674.558 3.9854136  7.255905  7.255905         0 .48979065  .4446395  1.0535954  .7690278  .9715392 1
2 24     10713               3571 1 0 1 0 1 0  3920.456  23.37209 16.113054 16.113054         0  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
3 24   469.386  67.05514513708833 0 1 1 1 0 0 249.85464 1.3868027         0  6.203494       100         0 .03939118   .2713815 .05203642         0 1
2 25      7984               3992 0 0 1 0 0 0 1106.0406 10.699284  5.834729 18.539408  68.52796  .4979894  .4166623  1.0871737  1.141407 1.0568452 1
3 25 1912.7562  478.1890697669486 0 1 0 0 0 0  628.4872  1.565503         0  9.807344       100         0  .4446395 .036324713 .07559729         0 1
3 26  1499.548 499.84928882347634 0 1 1 1 0 0  106.5086  .8697698         0  .6650236       100         0         0 .036324713 .07559729         0 1
2 26     15968               3992 1 0 1 0 1 0  2911.494  28.70453 17.163116 17.163116         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 27  198.9765  66.32550715898601 0 1 1 0 0 0  288.7973 1.0468845         0 21.279345       100         0         0          0  .1276337         0 1
2 27     19960               3992 0 0 1 1 1 0 4483.5405  21.17266   8.59867 18.254227  52.89491  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2 28     12411               4137 1 0 1 0 1 0  8559.486  40.70693  5.687073  5.687073         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 28 1254.6735  418.2244933639215 0 1 1 1 0 0  170.8057 1.1894264         0  9.221771       100         0  .4840307   .2713815 .23207135         0 1
3 29  500.0099  166.6699561345126 0 1 0 0 0 0  492.6128   1.30684         0  10.64039       100         0 .03939118 .036324713 .07559729         0 1
2 29     12411               4137 0 0 1 0 1 0  668.3796  8.492695 1.0805054  9.550291  88.68615  .4979894 1.0054207  1.0312163  1.141407 1.0568452 1
3 30 1658.1377    331.62753579493 0 1 0 0 0 0  254.4574  .9350939         0 12.768376       100         0         0          0         0         0 1
2 30     16548               4137 1 0 1 1 1 0  3613.546  19.52898   4.41039   4.41039         0  .9959788 1.1579261  1.0312163  1.141407 1.0568452 1
3 31 214.89786  71.63261944504583 0 1 1 0 0 0  1119.144  3.916241         0 10.640782       100         0 .03939118  .19264315 .28410777         0 1
2 31     20440               4088 1 0 1 1 1 0  3036.014 14.100977  7.234003  7.234003         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 32 1077.5896 179.59826930392802 0 1 1 0 0 0 195.32297  .7130032         0  7.013266       100         0         0          0  .1098652         0 1
2 33     12264               4088 1 0 1 0 1 0 2152.4937 12.673924  5.914581  5.914581         0  .9959788  .7491654  1.0871737  1.141407 1.0568452 1
3 33  9839.646  756.8958739989957 0 1 1 1 0 0  462.2032  .6046038         0 10.298324       100         0  .4840307          0  .1276337         0 1
3 34 1716.6117 429.15292887736524 0 1 0 1 0 0  487.7451  1.157661         0  5.985262       100         0 .03939118 .036324713  .1276337         0 1
3 35  1671.287 151.93516893205108 0 0 1 0 0 0 152.77376  .4980917         0 14.509166       100         0 .03939118          0  .8966615         0 1
2 35     16748               4187 1 0 1 0 1 0  2362.841  18.18688  4.620747   8.85564  47.82142  .9959788  .7491654  1.0871737  1.141407 1.0568452 1
2 36     16748               4187 0 0 1 0 1 0 1973.3223 10.554254 4.5894566  15.17669  69.75983  .9959788  .7491654  1.0871737  1.141407 1.0568452 1
3 36 1046.3352  523.1676168906002 0 1 0 0 0 0  442.4627  1.203434         0 23.940777       100         0         0 .036324713 .07559729         0 1
2 37     17132               4283 1 0 1 0 1 0 2421.6655  10.93265  7.123021  10.29919  30.83902  .9959788  .9016707  1.0312163  1.141407 1.0568452 1
2 38     21415               4283 1 0 1 1 1 0  2113.471 8.0428505  8.871873  8.871873         0  .9959788  .9016707  1.0312163  1.141407 1.0568452 1
3 38 2251.5735 375.26222884645364 0 1 1 1 0 0 219.87953  .8441113         0  1.330057       100         0         0 .036324713 .23207135         0 1
3 39  368.8428 184.42142466684328 0 0 1 0 0 0 182.03903  3.207241         0  19.95089       100         0 .03939118 .036324713  .5087809         0 1
2 39     25698               4283 1 0 1 0 1 0 2657.1565 13.512735   9.64428   9.64428         0  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
2 40     17280               4320 1 0 1 0 1 0  4558.719 20.595726  3.892079  6.009525 35.234837  .9959788  .4850084  1.0871737  1.141407 1.0568452 1
3 40  649.1291 108.18818389522322 0 1 0 0 0 0  368.9307  .3171265         0   2.99256       100         0         0          0 .07559729         0 1
3 41  94.42969  94.42968558771041 0 0 1 0 0 0  807.7322  6.715008   2.90226 31.631226   90.8247         0 .03939118   .4640247  .8210642  .9715392 1
2 42     17280               4320 0 0 1 0 1 0  2586.867   12.5366  2.798067  2.798067         0  .9959788 1.0054207  1.0871737  1.141407 1.0568452 1
3 42 172.74104  28.79017406906749 0 1 0 0 0 0  583.0478 1.3196278         0  5.320229       100         0         0          0  .1276337         0 1
3 43  23.06766 11.533829285696918 0 0 0 1 0 0 1047.1205   3.16955         0 17.562479       100         0 .03939118   .4640247 1.1213347  .6647144 1
2 43     20800               4160 1 0 1 0 1 1  9494.337  25.50727  5.277557  5.277557         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
2 44      8320               4160 1 0 1 1 1 0   2500.92 16.538345  7.848084 14.200424  44.73345  .9959788 1.0054207  1.0871737  1.141407 1.0568452 1
3 44  200.2767  16.68972373296003 0 1 1 1 0 0  645.3735 2.5972414         0  13.30027       100         0 .03939118          0 .07559729         0 1
2 45      8320               4160 1 0 1 0 1 0  8982.177 30.914375  7.850968  7.850968         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 45 2003.6993  500.9248353781869 0 1 1 1 0 0  354.3586 1.4078302         0  8.811659       100         0 .03939118 .036324713  .5087809         0 1
3 46  46.13532 11.533829285696918 0 0 1 1 0 0 3353.0344  6.714738  1.814521  43.72498  95.85015         0  .9621986   .4640247 1.0692983  .9715392 1
2 46     17336               4334 0 0 1 0 1 0 2345.9333 11.387603 3.2842946  9.636634 65.918655  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
3 47 1048.0308 262.00769303322187 0 0 1 0 0 0  984.2567 1.1357415 1.0883415  27.02407   95.9727         0         0  .42769995  .1098652  .9715392 1
2 47     17336               4334 1 0 1 0 1 0  4231.134 15.987907  12.28402  12.28402         0  .9959788  .5691676  1.0871737  1.141407 1.0568452 1
3 48 1329.1782 443.05938999110083 0 1 1 0 0 0  179.5634 1.0953367  1.282422  9.262705    86.155         0         0 .036324713         0         0 1
2 48     13002               4334 1 0 1 0 1 0  8189.632  22.83692 4.3790593 4.3790593         0  .9959788  .4166623  1.0871737  1.141407 1.0568452 1
3 49  3171.027 396.37840963814534 0 1 1 1 0 0 259.50516  2.443536  .4809069   12.4513   96.1377         0  .4840307  .22896788 .28410777         0 1
2 49     15860               3965 1 0 1 1 1 0  3167.883  13.12109 4.1131306 4.1131306         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 50  2269.932 453.98637141638096 0 1 0 0 0 0  86.58177 .53048944         0 3.1920924       100         0 .03939118 .036324713 .28410777         0 1
2 50     15860               3965 1 0 1 0 1 0      2757 19.330034  4.794142  4.794142         0  .9959788 1.1579261  1.0871737  1.141407 1.0568452 1
3 51 1547.2283 386.80706176179444 0 1 1 0 0 0  462.0626 1.3894062         0  8.811507       100         0         0 .036324713  .2085105         0 1
2 51      7930               3965 1 0 1 1 1 0  2678.802  13.44855  6.767579  6.767579         0  .9959788 1.0054207  1.0871737  1.141407 1.0568452 1
3 52  944.2969  94.42968558771041 0 0 1 0 0 0   23.9846 1.4578693  .3847258  9.322626  95.87321         0  .4840307  .19264315 1.0457374         0 1
2 52     24528               4088 0 0 1 0 1 0  4226.907 14.579534 1.9336625  5.745066   66.3422  .9959788  .9016707  1.0871737  1.141407 1.0568452 1
2 53     16352               4088 0 0 1 1 1 0 2271.5032  7.863501 1.3990335  7.395323  81.08218  .4979894  .7491654  1.0871737  1.141407 1.0568452 1
3 53  443.9513 110.98782643380137 0 1 1 1 0 0 1106.8425  .7635536         0 3.9900694       100         0         0 .036324713  .1506817         0 1
2 54     20440               4088 0 0 1 1 1 0 1116.6393  5.739378 .48622745  5.283259  90.79683         0  .7491654   .7811659  1.141407 1.0568452 1
3 54 179.26085  89.63042444608068 0 0 0 0 0 0  920.1736  2.588564         0  19.95083       100         0 .03939118 .036324713  .2085105         0 1
end
label values country_id country
label def country 2 "Vietnam", modify
label def country 3 "Zambia", modify
label values achieved_all achieved_all
label def achieved_all 0 "Not achieved", modify
label def achieved_all 1 "Achieved", modify
label values Bicycle V06_05
label values Motor_cycle V06_05
label values car_all_type V06_05
label def V06_05 1 "yes", modify
Thank you in advance!

Copy multiple variables

$
0
0
I have a question which might appear silly. I have hundreds of variables named *1001 and hundreds named *1003. The numbers are for two different weeks (1001 and 1003), and the wildcard stands in for many different things, such as hemoglobin levels and IL-6 levels, i e hb1001, il61001, hb1003, il61003.

In all cases the *1001 variables are the first recorded when they exist, but some patients only have measurements at week 1003 (the *1003 variables). I simply want to mass create a set of variables named *1000 with the *1001 values when they exist, and the rest with *1003. I could not find a way to perform a mass generation of variables. Forgive me for being so dim, but I have searched and googled to no avail. I would be thankful for your help.

Best analysis of log-transformed titers as dependent variable

$
0
0
Hello,
Apologies if this is a simple question, but I have been doubting myself as to how to proceed.
Current dataset includes log transformed quantitative titer values based on ELISA results (range = 2.3547321 to 4.5065505), and "negligible" has been replaced by 0, and "too high" by an arbitrary high value (in this case 6).

Independents of interest include: month sampled (categorical, 6 levels), age (continuous), vaccinated (y/n). Repeated measures are also a factor as the population (380 individuals) were sampled 6 times (variable "month"). There are 1831 data points in total.


1) I want to confirm that linear regression (glm) is the correct coding to use to explore these continuous data.
Therefore, would an appropriate analysis be:
e.g. glm logigga vaccinated ? or "regress"?

2) Also, it was recommended that I categorize this results into quantiles (ideally 4: low titer, slight, moderate, high titer), however, I seem to lose the variability when I then run the "melogit"
.
xtile iggagroups = logigga, nq(4)

. melogit iggagroups
outcome does not vary; remember:
0 = negative outcome,
all other nonmissing values = positive outcome
r(2000);


All I can think is that the analysis is comparing the group frequency, not the mean value of the titer in each quantile?

. tab iggagroups

4 quantiles |
of logigga | Freq. Percent Cum.
------------+-----------------------------------
1 | 458 25.01 25.01
2 | 458 25.01 50.03
3 | 458 25.01 75.04
4 | 457 24.96 100.00
------------+-----------------------------------
Total | 1,831 100.00


Any suggestions on how I can work through this data would be very welcome!

Help with the eform option of regress, geometric means

$
0
0
Hello,

I´m trying to obtain the geometric means and 95% CI with the eform option of regress. I´m working with log-transformed biomarkers and 3 eating groups. I have read the "Stata tip 1: The eform() option of regress" from Newson, 2003 but have problems working with it.

This is my syntax:

regress lnglucose w17age w17sex i.eatinggroup, noconstant eform(GM/Ratio) robust

-----------------------------------------------------------------------------
| Robust
lnglucose | GM/Ratio Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
w17age| 1.001799 .0002353 7.65 0.000 1.001338 1.002261
w17sex | .7707707 .0082473 -24.33 0.000 .7547574 .7871237
|
eatinggroup |
2 | 1.003426 .0122826 0.28 0.780 .9796131 1.027817
3 | 1.004425 .0145342 0.31 0.760 .9763085 1.033351
------------------------------------------------------------------------------

My question is, how do I obtain the geometric means of the 3 eating groups from the regress command? Is there another way?

thanks

Merge Data - housing burden + Wharton Index

$
0
0
Dear all,
I am trying to merge data on the housing burden and the Wharton index. Both datasets include a geo ID that is composed of State, county and place code, as: 32(state)108(county)123445(place). I noticed my variables in the wharton dataset are not following the same units, for the place, if the place # does not have six units, they did not include zeros to keep the format.

The data looks like this:

Datafile 1:

Array

Datafile 2:

Array

I am struggling with this so I appreciate any suggestion to make both geoid a number of length 11.

I am sorry if this is not the best way to address this question. Thank you.

Merge Data - housing burden + Wharton Index

$
0
0
Dear all,
I am trying to merge data on the housing burden and the Wharton index. Both datasets include a geo ID that is composed of State, county, and place code, as: 32(state)108(county)123445(place). I noticed my variables in the Wharton dataset are not following the same units, for the place, if the place # does not have six units, they did not include zeros to keep the format.

The data looks like this:

Datafile 1:

Array

Datafile 2:

Array

I am struggling with this so I appreciate any suggestion to make both geoid a number of length 11.

I am sorry if this is not the best way to address this question. Thank you.

How do I use replace if function to go through several variables at once (i.e. variables 1 through 40)?

$
0
0
Hi I am trying to sort through a large amount of data and narrow it down. To give a clear example, I have variables 1 through 40 with each variable representing a diagnosis.

I am using the replace if function to narrow down the diagnoses I want to keep in my future analysis. So my do file looks something like this:

replace had_bleeding=1 if diagnosis1=="nosebleeding"
replace had_bleeding=1 if diagnosis2=="nosebleeding"

and so forth...

My question is if there is a way to run the code so I can go through variables 1 through 40 quickly, like:

replace had_bleeding=1 if diagnosis1 through diagnosis40=="nosebleeding"

Is there a good way to do this in STATA? Otherwise, I have to write each one independently which is time-consuming.

Would appreciate the help, thanks.
Viewing all 72803 articles
Browse latest View live


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