-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTATA_syntax_arguments.html
1370 lines (1338 loc) · 47.9 KB
/
STATA_syntax_arguments.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<title>Stata syntax</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style type="text/css">
body {
margin: 0;
font-family: Cambria; Arial;
font-size: 20px;
}
.main {
margin: 75px 20px 100px 20px;
}
.footer {
background-color: #1F456E;
position: fixed;
bottom: 0px;
width: 100%;
}
.footer a, .footer p {
font-size: 60%;
color: white;
text-align: center;
padding: 4px 10px;
display: inline-block;
float: right;
}
.navbar {
background-color: #1F456E;
position: fixed;
top: 0px;
width: 100%;
}
.navbar a, .dropdown .chapter {
font-size: 80%;
color: white;
text-align: center;
padding: 6px 10px;
display: inline-block;
}
.navbar a {
background-color: #151E3D;
font-weight: bold;
float: left;
text-decoration: none;
}
.dropdown {
float: left;
overflow: hidden;
}
.navbar a:hover, .dropdown:hover .chapter {
background-color: #9B1003;
}
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 80px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
float: none;
font-weight: normal;
display: block;
text-align: left;
background-color: #1F456E;
}
.dropdown-content a:hover {
background-color: #151E3D;
}
.dropdown:hover .dropdown-content {
display: block;
}
h1, h2, h3, .title {
color:black;
font-weight:bold;
font-size: 100%;
padding: 2px;
margin: -40px 0 0 0;
}
h1::before, h2::before, h3::before {
padding-top:75px;
display:block;
content:"";
}
.title {
font-size:250%;
border: none;
text-align: center;
}
.subtitle {
text-align: center;
}
h1 {
font-size:120%;
border-bottom:1.5px solid black;
}
h2 {
font-size: 110%;
}
p, tr, li {
color:black;
font-size:80%;
margin: 0 0 5px 2px;
padding: 2px
}
ul {
margin: 0;
padding: 0 0 2px 25px;
}
li {
margin: 0;
padding: 0;
}
li li {
font-size: 100%;
padding: 0;
}
li .code {
font-size: 85%;
padding: 2px;
margin-top: 5px;
}
.code {
font-size:70%;
font-family:Courier New;
padding: 0;
margin: 0 0 2px 30px;
}
.indent {
margin-left:60px;
}
.spacer {
margin: 10px;
}
table {
border-collapse: collapse;
margin: 15px 0px 5px 15px;
}
tr {
font-size: 70%;
}
th, tr:last-child {
text-align: left;
border-bottom: 1px solid black;
}
td, th {
padding: 2px 10px 2px 2px;
vertical-align: top;
}
</style>
</head>
<body>
<div class="navbar">
<a href="#TOC0">Top</a>
<div class="dropdown">
<div class="chapter">General</div>
<div class="dropdown-content">
<a href="#TOC1">1. GENERAL</a>
<a href="#TOC1_1">1.1. Main window</a>
<a href="#TOC1_2">1.2. Data Editor</a>
<a href="#TOC1_3">1.3. Do-file Editor</a>
<a href="#TOC1_4">1.4. Viewer</a>
<a href="#TOC1_5">1.5. Graph Editor</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">Data</div>
<div class="dropdown-content">
<a href="#TOC2">2. DATA MODIFICATION</a>
<a href="#TOC2_1">2.1. Import Data</a>
<a href="#TOC2_2">2.2. Create Data</a>
<a href="#TOC2_3">2.3. Delete Data</a>
<a href="#TOC2_4">2.4. Data labels</a>
<a href="#TOC2_5">2.5. Limit data selection</a>
<a href="#TOC2_6">2.6. Range</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">Graphs:</div>
<div class="dropdown-content">
<a href="#TOC3">3. GENERAL GRAPH FORMATTING</a>
<a href="#TOC3_1">3.1. Text formatting</a>
<a href="#TOC3_2">3.2. Size formatting</a>
<a href="#TOC3_3">3.3. Colors</a>
<a href="#TOC3_4">3.4. Line and Marker style</a>
<a href="#TOC3_5">3.5. Add Titles, Lines or Text</a>
<a href="#TOC3_6">3.6. Graphregion and Plotregion</a>
<a href="#TOC3_7">3.7. Action</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">•Twoway</div>
<div class="dropdown-content">
<a href="#TOC4">4. TWOWAY GRAPHS</a>
<a href="#TOC4_1">4.1. Graph types</a>
<a href="#TOC4_2">4.2. Axis</a>
<a href="#TOC4_3">4.3. Legend</a>
<a href="#TOC4_4">4.4. Markers</a>
<a href="#TOC4_5">4.5. Marker labels</a>
<a href="#TOC4_6">4.6. Other types</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">•Other</div>
<div class="dropdown-content">
<a href="#TOC5">5. OTHER GRAPH TYPES</a>
<a href="#TOC5_1">5.1. Bar graphs</a>
<a href="#TOC5_2">5.2. Xtline graphs</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">•Combine</div>
<div class="dropdown-content">
<a href="#TOC6">6. COMBINE GRAPHS</a>
<a href="#TOC6_1">6.1. By() option</a>
<a href="#TOC6_2">6.2. Addplot</a>
<a href="#TOC6_3">6.3. Over() option</a>
<a href="#TOC6_4">6.4. Graph combine</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">•Examples</div>
<div class="dropdown-content">
<a href="#TOC7">7. GRAPH EXAMPLES</a>
<a href="#TOC7_1">7.1. Twoway graph</a>
<a href="#TOC7_2">7.2. Bar graph</a>
</div>
</div>
<div class="dropdown">
<div class="chapter">Statistics</div>
<div class="dropdown-content">
<a href="#TOC8">8. STATISTICS</a>
<a href="#TOC8_1">8.1. ANOVA</a>
<a href="#TOC8_2">8.2. Regress</a>
<a href="#TOC8_3">8.3. Pearson correlation</a>
</div>
</div>
</div>
<div class="footer">
<a href="https://www.stata.com/" target="_blank">Stata 17</a>
<p>Manual created by A.L.O. Gaenssle, 2023</p>
</div>
<div class="main">
<h1 id="TOC0" class="title">Stata syntax and arguments</h1>
<p class="subtitle">Created for <a href="https://www.stata.com/" target="_blank">Stata 17</a> by A.L.O. Gaenssle, 2023</p>
<h1 id="TOC1">1. GENERAL</h1>
<p>Stata has four main windows and a whole range of additional windows for manual processing. Most things can be conducted without scripting but Stata does encourage writing commands.</p>
<p class="spacer"></p>
<p>I primarily used Stata to create graphs using scripts I wrote. Therefore, this introduction in mainly focused on this explaining the syntax of graph commands.</p>
<h2 id="TOC1_1">1.1. Main window</h2>
<p>The main window from with all others are accessed</p>
<ul>
<li>The bottom section is a command line, simple commands can be written there directly but for more complex one, .do files are a better choice</li>
<li>The left area lists all conducted commands, clicking on them re-runs them</li>
<li>The center section lists all the conducted commands, processed .do files and all the results. Its especially helpful to learn new commands as all types of actions, appear here as commands</li>
</ul>
<h2 id="TOC1_2">1.2. Data Editor</h2>
<p>The data editor stores the input data as in a speadsheet</p>
<ul>
<li>It has two modes
<ul>
<li>Edit (pencil icon): lets you modify, add and delete the data</li>
<li>Browse (maginfer): it used for browsing and sorting data</li>
</ul>
</li>
</ul>
<h2 id="TOC1_3">1.3. Do-file Editor</h2>
<p>Do-files are the program scripts one can write to automate and speed up the processing</p>
<ul>
<li>// is used for comments</li>
<li>/// at the end of line (with leading space) is used to continue the script in the next line without breaking the line</li>
</ul>
<h2 id="TOC1_4">1.4. Viewer</h2>
<p>Stata has a very useful viewer to check all the operators and commands. Simply write:</p>
<p class="code">help [operator]</p>
<p class="code">→ help twoway</p>
<p>in the terminal in the main window to open the viewer.</p>
<h2 id="TOC1_5">1.5. Graph Editor</h2>
<p>Created graphs automatically appear in the graph viewer. Graphs can also be always opened there, regardless of the data currently loaded.</p>
<p>One want to manually edit the graph by clicking on the small graph icon in the task bar and starting the Graph Editor</p>
<ul>
<li>There, everything expect the data can be modified, including labels, ratios, colors and axes</li>
<li>The rest of Stata is locked as long at the Graph Editor is active</li>
<li>You can also record you edits</li>
</ul>
<h1 id="TOC2">2. DATA MODIFICATION</h1>
<h2 id="TOC2_1">2.1. Import Data</h2>
<p>There are three simple ways to import data in a table format.</p>
<ul>
<li>Import .csv files by clicking in ‘File’ in the task bar of the main window
<ul>
<li>> select ‘import’ > ‘Text data (delimited, *.csv, …)”</li>
</ul>
</li>
<li>Click on the spreadsheet icon with the pencil in the main window’s taskbar
<ul>
<li>> Copy paste the data from your spreadsheet to the Data Editor (it will ask if you want to treat the first line as variable names)</li>
</ul>
</li>
<li>Import the .csv file using the terminal and the file path, write (clear is for removing previous data):
</li>
</ul>
<p class="code indent">→ import delimited "/home/user/documents/ANOVA.csv", clear</p>
<h2 id="TOC2_2">2.2. Create Data</h2>
<ul>
<li>New variable:
<ul>
<li>generate: create variables with manual functions</li>
<li>egen: create new data based on extisting functions (only two are mentioned below, check help egen for more info)</li>
</ul>
</li>
<li>Alter variable:
<ul>
<li>New values: replace</li>
<li>New name: rename</li>
<li>New format: format</li>
</ul>
</li>
</ul>
<table>
<tr>
<th>Type</th>
<th>Operator</th>
<th>Example</th>
</tr>
<tr>
<td>mean</td>
<td>egen [var] = rowmean([varlist)</td>
<td>egen mean = rowmean(S1 S2) if sample</td>
</tr>
<tr>
<td>stdev</td>
<td>egen [var] = rowsd([varlist)</td>
<td>egen sd = rowsd(S1-S3)</td>
</tr>
<tr>
<td>mean + sd</td>
<td>generate [var] = [var1] + [var2]</td>
<td>generate posSD = mean + sd</td>
</tr>
<tr>
<td>replace</td>
<td>replace [var] = [exp]</td>
<td>replace Name = "Amylose III" if tmin == 1</td>
</tr>
<tr>
<td>rename</td>
<td>rename [var] [string]</td>
<td>rename id ID</td>
</tr>
<tr>
<td>format</td>
<td>format [varlist] [format]</td>
<td>format mean SD %5.2f</td>
</tr>
</table>
<h2 id="TOC2_3">2.3. Delete Data</h2>
<p>There are two types of operators, drop and keep. Drop deletes all in the selection, keep deletes all that doesn’t meet the selection.</p>
<table>
<tr>
<th>Data type</th>
<th>Meaning</th>
<th>Example</th>
</tr>
<tr>
<td>data (row)</td>
<td>drop in [rowlist]</td>
<td>drop in 400/500</td>
</tr>
<tr>
<td>variable (column)</td>
<td>drop [varlist]</td>
<td>drop t3-t9</td>
</tr>
<tr>
<td>variable (column)</td>
<td>keep if [exp]</td>
<td>keep if sample != "Test"</td>
</tr>
</table>
<h2 id="TOC2_4">2.4. Data labels</h2>
<p>In many cases (e.g. statistics, several types of graphs) the naming variable has to be a number. In order to still show the actual names instead of the numbers, data labels can be assigned to the variable. This is conducted in two steps, first the creation of an array and than the assignment of said array to the varribale.</p>
<p class="code">label define [arr] [1 "[string1]" 2 "[string2]" ...]</p>
<p class="code">label values [var] [arr]</p>
<p class="code">→ label define Name 1 "Corn starch" 2 "Pea starch" 3 "Potato starch"</p>
<p class="code">→ label values ID Name</p>
<p class="spacer"></p>
<p>Variables have sort of two names, the one with which you call in (usually lowercase, no spaces or special characters) and another which is displayed in the graphs. The second can be defined as followed:</p>
<p class="code">label variable [var] "[string]"</p>
<p class="code">→ label variable db "Degree of branching (%)"</p>
<h2 id="TOC2_5">2.5. Limit data selection</h2>
<p>Data can be selected by the usual operators</p>
<table>
<tr>
<th>Operator</th>
<th>Meaning</th>
<th>Example</th>
</tr>
<tr>
<td>==</td>
<td>equal to</td>
<td>if sample == 2</td>
</tr>
<tr>
<td>!=</td>
<td>not equal to</td>
<td>if sample != "Test"</td>
</tr>
<tr>
<td>< or <=</td>
<td>less (or equal)</td>
<td>if sample < 25</td>
</tr>
<tr>
<td>> or >=</td>
<td>greater (or equal)</td>
<td>if sample >= 10</td>
</tr>
<tr>
<td>&</td>
<td>and</td>
<td>if sample >= 10 & sample < 25</td>
</tr>
<tr>
<td>|</td>
<td>or</td>
<td>if sample < 25 | name != "Test"</td>
</tr>
</table>
<h2 id="TOC2_6">2.6. Range</h2>
<p>How to select the range depends on the type of data</p>
<table>
<tr>
<th>Data type</th>
<th>Meaning</th>
<th>Example</th>
</tr>
<tr>
<td>data (row)</td>
<td>min/max</td>
<td>drop in 400/500</td>
</tr>
<tr>
<td>variable (column)</td>
<td>min-max</td>
<td>drop t3-t9</td>
</tr>
<tr>
<td>variable (column)</td>
<td>var1 var2</td>
<td>keep name sample</td>
</tr>
<tr>
<td>axis</td>
<td>min(step)max</td>
<td>0(10)50</td>
</tr>
</table>
<h1 id="TOC3">3. GENERAL GRAPH FORMATTING</h1>
<p>There are seveal types of formatting options that apply to most graphs, that effect the text, size and color.</p>
<h2 id="TOC3_1">3.1. Text formatting</h2>
<p>You can find them and many more under</p>
<p class="code">help textbox_options</p>
<table>
<tr>
<th>Type</th>
<th>Operator</th>
<th>Example</th>
<th>Result</th>
</tr>
<tr>
<td>bold</td>
<td>{bf:[string]}</td>
<td>"{bf:Enzymes}"</td>
<td><b>Enzymes</b></td>
</tr>
<tr>
<td>italic</td>
<td>{it:[string]}</td>
<td>"{it:B. fibrisolvens}"</td>
<td><i>B. fibrisolvens</i></td>
</tr>
<tr>
<td>size</td>
<td>size([num])</td>
<td>size(3)</td>
<td>→ change font size</td>
</tr>
<tr>
<td>color</td>
<td>color([col])</td>
<td>color(black)</td>
<td>→ change font color</td>
</tr>
<tr>
<td>justification</td>
<td>justification([type])</td>
<td>Justification(left)</td>
<td>→ horizontal within textbox</td>
</tr>
<tr>
<td>alignment</td>
<td>alignment([type])</td>
<td>alignment(middle)</td>
<td>→ vertical within textbox</td>
</tr>
<tr>
<td>margin</td>
<td>margin([num])</td>
<td>margin(2)</td>
<td>→ between text and textbox border</td>
</tr>
<tr>
<td>placement</td>
<td>placement([pos])placement(c)</td>
<td>placement(c)</td>
<td>→ location of entire textbox</td>
</tr>
</table>
<h2 id="TOC3_2">3.2. Size formatting</h2>
<p>Size of the font, marker, line, etc can be changed in three different ways</p>
<p class="code">help size</p>
<ul>
<li>A defined size: [num]; e.g. size(2)
</li>
<li>A multiplier: *[num]; e.g. size(*2); this changes the size relative to the set one
</li>
<li>A type: [type]; e.g. size(medium), there is a whole range of named sizes
</li>
</ul>
<p class="code">help linewidthstyle</p>
<p class="code">help marginstyle</p>
<p class="code">help markersizestyle</p>
<h2 id="TOC3_3">3.3. Colors</h2>
<p>There are two different ways to set a color</p>
<p class="code">help colorstyle</p>
<ul>
<li>By defining the RGB, CMYK or HSV value (e.g. "32 206 250")
</li>
<li>Preset color:
<ul>
<li>There are many preset colors in default stata</li>
<li>See: <a href="http://1.bp.blogspot.com/-HAFAL8DGqtk/ViDL7QtayRI/AAAAAAAAACo/oNuFKuGsGJI/s1600/hue.jpg" target="_blank">Named colors in Stata</a></li>
<li>can further be manipulated by adding a muliplier (e.g. teal*1.5; marron*0.75)</li>
</ul>
</li>
</ul>
<h2 id="TOC3_4">3.4. Line and Marker style</h2>
<p>Both the lines and the marker (data markers) can be altered</p>
<ul>
<li>Line patterns (defined by a set name or a sequence)
<p class="code">help linepatternstyle</p>
<ul>
<li>name: e.g. solid, dash, dot</li>
<li>sequence: e.g. "_--" (a long dash followed by two short dashes)</li>
</ul>
</li>
<li>Marker style (defined by a name or a abbr.)
<p class="code">help symbolstyle</p>
<ul>
<li>common names are (circle, diamond, triangle, square, pipe)</li>
<li>common abbr. for solid icons are (O, D, T, S, |), for hollow icons are (Oh, Dh, Th, Sh)</li>
<li>small cap letters create smaller markers</li>
</ul>
</li>
</ul>
<h2 id="TOC3_5">3.5. Add Titles, Lines or Text</h2>
<p>Titles, lines and textboxes can be added to each graph</p>
<p class="code">help title_options</p>
<p class="code">help added_line_options</p>
<p class="code">help added_text_options</p>
<table>
<tr>
<th>Syntax</th>
<th>Description</th>
<th>Example</th>
</tr>
<tr>
<td>title([string], [options])</td>
<td>add overall title</td>
<td>title("{bf:A}", axis(1) color(black) position(11) size(4))</td>
</tr>
<tr>
<td>xtitle([string], size(#))</td>
<td>add title to x-axis</td>
<td>ytitle(Wavelength (nm), size(3))</td>
</tr>
<tr>
<td>ytitle( "`: var label [var]'")</td>
<td>show variables as heading of by()-graphs</td>
<td>ytitle( "`: var label protein'")</td>
</tr>
<tr>
<td>subitle([string], [options])</td>
<td>add a subtitle</td>
<td>subtitle("{bf:Standard - 1st run}", placement(nwest) size(4))</td>
</tr>
<tr>
<td>yline([x-pos], [options])</td>
<td>add a horizontal line</td>
<td>yline(0, lcolor(black))</td>
</tr>
<tr>
<td>xline([y-pos], [options])</td>
<td>add a vertical line</td>
<td>xline(6.374, lcolor(red*2) lw(vthin))</td>
</tr>
<tr>
<td>text([x] [y] [string], [options])</td>
<td>add a textbox</td>
<td>text(320 70 "Debranched-Blank", size(2.5) placement(w))</td>
</tr>
</table>
<h2 id="TOC3_6">3.6. Graphregion and Plotregion</h2>
<p>The graph region is the complete area of the entire figure, including all axis, legends and titles and the plot region is only the graph itself (the displayed data points).</p>
<ul>
<li>The margin of the graph region is the space between the edge of the figure and the rest</li>
<li>The margin of the plot region is the space between the graph and the axis and borders</li>
</ul>
<p class="code">help region_options</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>graphregion(color(white) margin(medsmall) lpattern(blank))</td>
<td>make the area around the graph white and remove lines</td>
</tr>
<tr>
<td>plotregion(margin(small))</td>
<td>decrease the margin between graph and axis</td>
</tr>
<tr>
<td>fxsize(95) fysize(91)</td>
<td>forze size</td>
</tr>
<tr>
<td>aspectratio(0.6)</td>
<td>ratio between x and y dimensions</td>
</tr>
</table>
<h2 id="TOC3_7">3.7. Action</h2>
<p>There are several general actions one usually needs, especially regarding saving the graphs</p>
<p class="code">help graph export</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>saving("X:\PhD\Graph1.gph", replace)</td>
<td>save the graph during building and replace the pervious version</td>
</tr>
<tr>
<td>graph save Graph "/home/PhD/Areas_mean.gph", replace</td>
<td>save the graph after it was created, if the graph was not named, its default name is “Graph”</td>
</tr>
<tr>
<td>graph export "X:\PhD\Graph.png", as(png) width(1700) height(1200)</td>
<td>export the graph as png with specified dimensions, the graph is not named as it just exports the active one</td>
</tr>
<tr>
<td>nodraw</td>
<td>don’t visually create the graph, used with graph combine</td>
</tr>
<tr>
<td>name(Gprotein, replace)</td>
<td>name the graph, used for graph combine</td>
</tr>
</table>
<h1 id="TOC4">4. TWOWAY GRAPHS</h1>
<p>Twoway graphs are almost all graphs that take in two correlated numerical variables, e.g. scatter, line, area and range plots. There is a whole range of different types of graphs. Useful links to get an idea are:</p>
<p class="code">help graph_twoway</p>
<ul>
<li><a href="https://www.stata.com/support/faqs/graphics/gph/stata-graphs/" target="_blank">Stata graphs</a></li>
<li><a href="https://stats.oarc.ucla.edu/stata/modules/graph8/twoway/" target="_blank">Twoway graphs</a></li>
<li><a href="https://stats.oarc.ucla.edu/stata/modules/graph8/intro/introduction-to-graphs-in-stata/" target="_blank">Introduction to graphs in stata</a></li>
<li>You can test out the graphs by using the default test data
</li>
</ul>
<p class="code indent">→ sysuse auto.dta</p>
<h2 id="TOC4_1">4.1. Graph types</h2>
<p>The syntax for creating twoway graphs is</p>
<p class="code">twoway [graph type] [y-list] [x], [options]</p>
<p class="code">twoway [graph type] [y-list] [x] if [exp], [options]</p>
<p class="spacer"></p>
<p>Examples</p>
<p class="code">→ scatter wavelength absorbance if sample==1, msymbol(O) msize(2.5)</p>
<p class="code">→ rarea posSD negSD wavelength if sample==1, sort horizontal</p>
<p class="code">→ twoway bar mean ID, by(enzyme) barwidth(0.75) color(red*2)</p>
<p class="code">→ twoway rbar mean posSD ID, lcolor(black) fcolor(none) barwidth(0.6)</p>
<p class="code">→ twoway connected branching time, yaxis(1) mcolor(blue*1.5) lcolor(blue*1.5)</p>
<h2 id="TOC4_2">4.2. Axis</h2>
<h3 id="TOC4_2_1">4.2.1. Axis labels options</h3>
<p>This subset of options affest the number and style of the ticks of an axis and the associated labels</p>
<p class="code">help axis_label_options</p>
<p class="code">xlabel(#(#)#, options)</p>
<p class="code">→ ylabel(0(10)50), format(%5.2f) nogrid labsize(3))</p>
<p class="code">→ xlabel(#8, noticks grid valuelabel)</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
<th>Options</th>
</tr>
<tr>
<td>xlabel(#6)</td>
<td>six major ticks</td>
<td></td>
</tr>
<tr>
<td>xmtick(##5)</td>
<td>five minor ticks</td>
<td></td>
</tr>
<tr>
<td>axis(1)</td>
<td>select axis (if there are multiple)</td>
<td></td>
</tr>
<tr>
<td>format(%#.#f)</td>
<td>format numbers</td>
<td>format(%5.2f) -> 15000.00</td>
</tr>
<tr>
<td>valuelabel</td>
<td>use value labels of variable</td>
<td></td>
</tr>
<tr>
<td>angle(0)</td>
<td>angle of labels</td>
<td>imargin(1 1 1 1) or imargin(vsmall)</td>
</tr>
<tr>
<td>alternate</td>
<td>offset adjacent labels</td>
<td>graphregion(color(white))</td>
</tr>
<tr>
<td>noticks</td>
<td>hide ticks</td>
<td>ticks → show ticks</td>
</tr>
<tr>
<td>nogrid</td>
<td>hide grid</td>
<td>xsize(5.5) ysize(5)</td>
</tr>
<tr>
<td>labcolor(black)</td>
<td>change color of the labels</td>
<td></td>
</tr>
<tr>
<td>labsize(3)</td>
<td>set size of labels</td>
<td></td>
</tr>
<tr>
<td>tlcolor(blue*1.5)</td>
<td>set tick color</td>
<td></td>
</tr>
<tr>
<td>tlength(*1.5)</td>
<td>alter the length of the tick</td>
<td></td>
</tr>
<tr>
<td>tlwidth</td>
<td>alter the width ot the ticks</td>
<td></td>
</tr>
</table>
<h3 id="TOC4_2_2">4.2.2. Axis scale options</h3>
<p>This set of options target the range of the axis, the style of the line and the surrounding gaps</p>
<p class="code">help axis_scale_options</p>
<p class="code">xscale([options])</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>axis(1)</td>
<td>select axis (if there are multiple)</td>
</tr>
<tr>
<td>range(1 10)</td>
<td>expand axis to given range</td>
</tr>
<tr>
<td>reverse</td>
<td>reverse scale to run from max to min</td>
</tr>
<tr>
<td>alt</td>
<td>move axis from left to right or from top to bottom</td>
</tr>
<tr>
<td>noline</td>
<td>hide line</td>
</tr>
<tr>
<td>noextend</td>
<td>do not extend the line</td>
</tr>
<tr>
<td>titlegap(2)</td>
<td>gap between title and labels</td>
</tr>
<tr>
<td>outergap(0)</td>
<td>gap between title and graph border</td>
</tr>
<tr>
<td>lcolor(black)</td>
<td>color of the axis line</td>
</tr>
<tr>
<td>lwidth(thin)</td>
<td>thickness of the axis line</td>
</tr>
</table>
<h2 id="TOC4_3">4.3. Legend</h2>
<p>Legend options changes everything within the legend box and its placement</p>
<p class="code">help legend_options</p>
<p class="code">legend(options)</p>
<p class="code">→ legend(col(2) colfirst /// order(- "{bf:Branching enzymes}" 7 "{it:B. fibrisolvens}" /// 8 "{it:T. kodakarensis}") size(4)) ///</p>
<p class="code">→ legend(col(6) colfirst symysize(*0.05) size(4) col(1) /// subtitle("Time (min)", size(4))</p>
<p class="code">→ legend(col(2) colfirst size(3) region(lcolor(white)) /// symxsize(*0.5) holes(5 9) /// order(- "GH13:" 1 2 3 - "GH57:" 4 5 6)) ///</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>off</td>
<td>hide legend</td>
</tr>
<tr>
<td>position(12)</td>
<td>location of legend by clock position</td>
</tr>
<tr>
<td>at(3)</td>
<td>position of legend as "graph" -> insert into hole in by()-graph</td>
</tr>
<tr>
<td>cols(2) rows(3)</td>
<td>number of columns and rows</td>
</tr>
<tr>
<td>colfirst</td>
<td>fill columns first</td>
</tr>
<tr>
<td>width(30) height(3)</td>
<td>dimensions of the legend</td>
</tr>
<tr>
<td>span</td>
<td>center legend</td>
</tr>
<tr>
<td>outergap(0)</td>
<td>gap between title and graph border</td>
</tr>
<tr>
<td>lcolor(black)</td>
<td>color of the axis line</td>
</tr>
<tr>
<td>region(lc(white) margin(large))</td>
<td>no border, large margin</td>
</tr>
<tr>
<td>size(#)</td>
<td>textsize</td>
</tr>
<tr>
<td>symysize(*0.05) symxsize(2)</td>
<td>dimesions of symbols in legend</td>
</tr>
<tr>
<td>order(- “All” 1 “Start” 2 “End”</td>
<td>Relabel and reorder all labels “-” inserts a subtitle at this position</td>
</tr>
<tr>
<td>subtitle("Time (min)", size(3.5))</td>
<td>add subtitle to legend</td>
</tr>
</table>
<h2 id="TOC4_4">4.4. Markers</h2>
<p>The markers are the symbols of the data points (e.g. in scatter plots). The options are direclty added to the rest of the graph options. Each data set (e.g. sample) has to addressed individually by writing all of them in a row in the parantheses</p>
<p class="code">help marker_options</p>
<p class="code">→ pcarrow ay2 ax2 ay1 ax1, lc(black) mcolor(black) mangle(22) /// barbsize(thick) msize(medium) lwidth(thin))</p>
<p class="code">→ scatter wlmean abmean if sample==10, msym(T) msize(2) /// mcolor(gs8) mlwidth(medthick)</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>msymbols(O)</td>
<td>type of symbol → See Section <a href="#TOC3_4">3.4</a>
<td>msize(2.5)</td>
<td>size of marker</td>
</tr>
<tr>
<td>mcolor(blue*1.5)</td>
<td>color of the entire marker</td>
</tr>
<tr>
<td>mfcolor(black grey)</td>
<td>fill color (of two data sets)</td>
</tr>
<tr>
<td>mlcolor(gs6)</td>
<td>color of the outline</td>
</tr>
<tr>
<td>mlwidth(thin thin thin)</td>
<td>thickness of the marker outline (set all three to thin)</td>
</tr>
<tr>
<td>mangle(22)</td>
<td>angle of the marker</td>
</tr>
<tr>
<td>barbsize(thick)</td>
<td>for twoway pcarrow (size of filled portion of arrowhead)</td>
</tr>
</table>
<h2 id="TOC4_5">4.5.</a>Marker labels</h2>
<p>Labels can be added to each marker using a variable and can be formatted as other text but each data set (e.g. sample) has to addressed individually by appending them (like the markers)</p>
<p class="code">help marker_label_options</p>
<table>
<tr>
<th>Example</th>
<th>Description</th>
</tr>
<tr>
<td>mlabel(samples)</td>
<td>use the variable “samples” to label the data points</td>
</tr>
<tr>
<td>mlabposition(12)</td>
<td>position the labels north of the markers</td>
</tr>
<tr>
<td>mlabangle(0 45)</td>
<td>angle the labels of the second data set at 45°</td>
</tr>
<tr>
<td>mlabcolor(blue*2 green purple)</td>
<td>color the labels blue, green and purple</td>
</tr>
<tr>
<td>mlabsize(3)</td>
<td>font size</td>
</tr>