File: gretl_gui_fnref.en

package info (click to toggle)
gretl 2022c-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 59,552 kB
  • sloc: ansic: 409,074; sh: 4,449; makefile: 3,222; cpp: 2,777; xml: 599; perl: 364
file content (6153 lines) | stat: -rw-r--r-- 323,509 bytes parent folder | download
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
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
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153

## Accessors

# $ahat access
Output: 	series 

Must follow the estimation of a fixed-effects or random-effects panel data model. Returns a series containing the estimates of the individual effects. 

# $aic access
Output: 	scalar 

Returns the Akaike Information Criterion for the last estimated model, if available. See chapter 28 of the <@pdf="Gretl User's Guide#chap:criteria"> for details of the calculation. 

# $bic access
Output: 	scalar 

Returns Schwarz's Bayesian Information Criterion for the last estimated model, if available. See chapter 28 of the <@pdf="Gretl User's Guide#chap:criteria"> for details of the calculation. 

# $chisq access
Output: 	scalar 

Returns the overall chi-square statistic from the last estimated model, if available. 

# $coeff access
Output: 	matrix or scalar 
Argument: 	<@var="s">  (name of coefficient, optional)

With no arguments, <@lit="$coeff"> returns a column vector containing the estimated coefficients for the last model. With the optional string argument it returns a scalar, namely the estimated parameter named <@var="s">. See also <@ref="$stderr">, <@ref="$vcv">. 

Example: 

<code>          
     open bjg
     arima 0 1 1 ; 0 1 1 ; lg
     b = $coeff               # gets a vector
     macoef = $coeff(theta_1) # gets a scalar
</code>

If the “model” in question is actually a system, the result depends on the characteristics of the system: for VARs and VECMs the value returned is a matrix with one column per equation, otherwise it is a column vector containing the coefficients from the first equation followed by those from the second equation, and so on. 

# $command access
Output: 	string 

Must follow the estimation of a model; returns the command word, for example <@lit="ols"> or <@lit="probit">. 

# $compan access
Output: 	matrix 

Must follow the estimation of a VAR or a VECM; returns the companion matrix. 

# $datatype access
Output: 	scalar 

Returns an integer value representing the sort of dataset that is currently loaded: 0 = no data; 1 = cross-sectional (undated) data; 2 = time-series data; 3 = panel data. 

# $depvar access
Output: 	string 

Must follow the estimation of a single-equation model; returns the name of the dependent variable. 

# $df access
Output: 	scalar 

Returns the degrees of freedom of the last estimated model. If the last model was in fact a system of equations, the value returned is the degrees of freedom per equation; if this differs across the equations then the value given is the number of observations minus the mean number of coefficients per equation (rounded up to the nearest integer). 

# $diagpval access
Output: 	scalar 

Must follow estimation of a system of equations. Returns the <@mth="P">-value associated with the <@ref="$diagtest"> statistic. 

# $diagtest access
Output: 	scalar 

Must follow estimation of a system of equations. Returns the test statistic for the null hypothesis that the cross-equation covariance matrix is diagonal. This is the Breusch–Pagan test except when the estimator is (unrestricted) iterated SUR, in which case it is a Likelihood Ratio test. See chapter 34 of the <@pdf="Gretl User's Guide#chap:system"> for details; see also <@ref="$diagpval">. 

# $dotdir access
Output: 	string 

This accessor returns the path where gretl stores temporary files, for example when using the <@ref="mwrite"> function with a non-zero third argument. 

# $dw access
Output: 	scalar 

Returns the Durbin–Watson statistic for first-order serial correlation from the model last estimated (if available). 

# $dwpval access
Output: 	scalar 

Returns the CDF of the Durbin–Watson distribution evaluated at the DW statistic for the model last estimated (if available), computed using the <@bib="Imhof;imhof61"> procedure. This is the p-value for a one-sided test with an alternative of positive first-order autocorrelation. If you want the p-value for a two-sided test, take 2<@mth="P"> if DW < 2 or 2(1 – <@mth="P">) if DW > 2, where <@mth="P"> is the value returned by the accessor. 

Due to the limited precision of digital arithmetic, the Imhof integral can go negative when the Durbin–Watson statistic is close to its lower bound. In that case the accessor returns <@lit="NA">. Since any other failure mode results in an error being flagged it is probably safe to assume that an NA value means the true p-value is “very small”, although we are unable to quantify it. 

# $ec access
Output: 	matrix 

Must follow the estimation of a VECM; returns a matrix containing the error correction terms. The number of rows equals the number of observations used and the number of columns equals the cointegration rank of the system. 

# $error access
Output: 	scalar 

Returns the program's internal error code, which will be non-zero in case an error has occurred but has been trapped using <@xrf="catch">. Note that using this accessor causes the internal error code to be reset to zero. If you want to get the error message associated with a given <@lit="$error"> you need to store the value in a temporary variable, as in 

<code>          
     err = $error
     if (err)
         printf "Got error %d (%s)\n", err, errmsg(err);
     endif
</code>

See also <@xrf="catch">, <@ref="errmsg">. 

# $ess access
Output: 	scalar 

Returns the error sum of squares of the last estimated model, if available. 

# $evals access
Output: 	matrix 

Must follow the estimation of a VECM; returns a vector containing the eigenvalues that are used in computing the trace test for cointegration. 

# $fcast access
Output: 	matrix 

Must follow the <@xrf="fcast"> forecasting command; returns the forecast values as a matrix. If the model on which the forecast was based is a system of equations the returned matrix will have one column per equation, otherwise it is a column vector. 

# $fcse access
Output: 	matrix 

Must follow the <@xrf="fcast"> forecasting command; returns the standard errors of the forecasts, if available, as a matrix. If the model on which the forecast was based is a system of equations the returned matrix will have one column per equation, otherwise it is a column vector. 

# $fevd access
Output: 	matrix 

Must follow estimation of a VAR. Returns a matrix containing the forecast error variance decomposition (FEVD). This matrix has <@mth="h"> rows where <@mth="h"> is the forecast horizon, which can be chosen using <@lit="set horizon"> or otherwise is set automatically based on the frequency of the data. 

For a VAR with <@mth="p"> variables, the matrix has <@mth="p"><@sup="2"> columns: the first <@mth="p"> columns contain the FEVD for the first variable in the VAR; the second <@mth="p"> columns the FEVD for the second variable; and so on. The (decimal) fraction of the forecast error for variable <@mth="i"> attributable to innovation in variable <@mth="j"> is therefore found in column (<@mth="i"> – 1)<@mth="p"> + <@mth="j">. 

For a more flexible variant of this functionality, see the <@ref="fevd"> function. 

# $Fstat access
Output: 	scalar 

Returns the overall F-statistic from the last estimated model, if available. 

# $gmmcrit access
Output: 	scalar 

Must follow a <@lit="gmm"> block. Returns the value of the GMM objective function at its minimum. 

# $h access
Output: 	series 

Must follow a <@lit="garch"> command. Returns the estimated conditional variance series. 

# $hausman access
Output: 	row vector 

Must follow estimation of a model via either <@lit="tsls"> or <@lit="panel"> with the random effects option. Returns a 1×3 vector containing the value of the Hausman test statistic, the corresponding degrees of freedom and the p-value for the test, in that order. 

# $hqc access
Output: 	scalar 

Returns the Hannan-Quinn Information Criterion for the last estimated model, if available. See chapter 28 of the <@pdf="Gretl User's Guide#chap:criteria"> for details of the calculation. 

# $huge access
Output: 	scalar 

Returns a very large positive number. By default this is 1.0E100, but the value can be changed using the <@xrf="set"> command. 

# $jalpha access
Output: 	matrix 

Must follow the estimation of a VECM, and returns the loadings matrix. It has as many rows as variables in the VECM and as many columns as the cointegration rank. 

# $jbeta access
Output: 	matrix 

Must follow the estimation of a VECM, and returns the cointegration matrix. It has as many rows as variables in the VECM (plus the number of exogenous variables that are restricted to the cointegration space, if any), and as many columns as the cointegration rank. 

# $jvbeta access
Output: 	square matrix 

Must follow the estimation of a VECM, and returns the estimated covariance matrix for the elements of the cointegration vectors. 

In the case of unrestricted estimation, this matrix has a number of rows equal to the unrestricted elements of the cointegration space after the Phillips normalization. If, however, a restricted system is estimated via the <@lit="restrict"> command with the <@lit="--full"> option, a singular matrix with <@mth="(n+m)r"> rows will be returned (<@mth="n"> being the number of endogenous variables, <@mth="m"> the number of exogenous variables that are restricted to the cointegration space, and <@mth="r"> the cointegration rank). 

Example: the code 

<code>          
     open denmark.gdt
     vecm 2 1 LRM LRY IBO IDE --rc --seasonals -q
     s0 = $jvbeta

     restrict --full
       b[1,1] = 1
       b[1,2] = -1
       b[1,3] + b[1,4] = 0
     end restrict
     s1 = $jvbeta

     print s0
     print s1
</code>

produces the following output. 

<code>          
     s0 (4 x 4)

          0.019751     0.029816  -0.00044837   -0.12227
          0.029816     0.31005   -0.45823      -0.18526
         -0.00044837  -0.45823    1.2169       -0.035437
         -0.12227     -0.18526   -0.035437      0.76062

     s1 (5 x 5)

     0.0000       0.0000       0.0000       0.0000       0.0000
     0.0000       0.0000       0.0000       0.0000       0.0000
     0.0000       0.0000      0.27398     -0.27398    -0.019059
     0.0000       0.0000     -0.27398      0.27398     0.019059
     0.0000       0.0000    -0.019059     0.019059    0.0014180
</code>

# $lang access
Output: 	string 

Returns a string representing the national language in force currently, if this can be determined. The string is composed of a two-letter ISO 639-1 language code (for example, <@lit="en"> for English, <@lit="jp"> for Japanese, <@lit="el"> for Greek) followed by an underscore plus a two-letter ISO 3166-1 country code. Thus for example Portuguese in Portugal gives <@lit="pt_PT"> while Portuguese in Brazil gives <@lit="pt_BR">. 

If the national language cannot be determined, the string “<@lit="unknown">” is returned. 

# $llt access
Output: 	series 

For selected models estimated via Maximum Likelihood, returns the series of per-observation log-likelihood values. At present this is supported only for binary logit and probit, tobit and heckit. 

# $lnl access
Output: 	scalar 

Returns the log-likelihood for the last estimated model (where applicable). 

# $macheps access
Output: 	scalar 

Returns the value of “machine epsilon”, which gives an upper bound on the relative error due to rounding in double-precision floating point arithmetic. 

# $mapfile access
Output: 	string 

If data from a GeoJSON file or ESRI shapefile have been loaded, returns the name of the file that should be opened to obtain the map polygons, otherwise returns an empty string. This is designed for use with the <@ref="geoplot"> function. 

# $mnlprobs access
Output: 	matrix 

Following estimation of a multinomial logit model (only), retrieves a matrix holding the estimated probabilities of each possible outcome at each observation in the model's sample range. Each row represents an observation and each column an outcome. 

# $model access
Output: 	bundle 

Must follow estimation of a single-equation model; returns a bundle containing many items of data pertaining to the model. All the regular model accessors are included: these are referenced by keys that are the same as the regular accessor names, minus the leading dollar sign. So for example the residuals appear under the key <@lit="uhat"> and the error sum of squares under <@lit="ess">. 

Depending on the estimator, additional information may be available; the keys for such information should hopefully be fairly self-explanatory. To see what's available you can get a copy of the bundle and print its content, as in 

<code>          
     ols y 0 x
     bundle b = $model
     print b
</code>

# $mpirank access
Output: 	integer 

If gretl is built with MPI support, and the program is running in MPI mode, returns the 0-based “rank” or ID number of the current process. Otherwise returns –1. 

# $mpisize access
Output: 	integer 

If gretl is built with MPI support, and the program is running in MPI mode, returns the number of MPI processes currently running. Otherwise returns 0. 

# $ncoeff access
Output: 	integer 

Returns the total number of coefficients estimated in the last model. 

# $nobs access
Output: 	integer 

Returns the number of observations in the currently selected sample. Related: <@ref="$tmax">. 

In the case of panel data the value returned is the number of pooled observations (number of units times number of observations per unit). If you want the time-series length of a panel use <@ref="$pd">, and the number of included units can be found as <@lit="$nobs"> divided by <@lit="$pd">. 

# $now access
Output: 	vector 

Returns a 2-vector: its first element is the number of seconds elapsed since 1970-01-01 00:00:00 +0000 (UTC, or Coordinated Universal Time), which is widely used in the computing world to represent the current time, and the second is the current date in ISO 8601 “basic” format, <@lit="YYYYMMDD">. The <@ref="strftime"> function may be used to process the first element, and <@ref="epochday"> may be used to process the second. 

# $nvars access
Output: 	integer 

Returns the number of series in the dataset (including the constant). Since <@lit="const"> is always present in any dataset a return value of 0 indicates that no dataset is in place. Note that if this accessor is used within a function, the number of series currently accessible may well fall short of that given by <@lit="$nvars">. 

# $obsdate access
Output: 	series 

Applicable when the current dataset is time-series with annual, quarterly, monthly or decennial frequency, or is dated daily or weekly, or when the dataset is a panel with time-series information set appropriately (see the <@xrf="setobs"> command). The returned series holds 8-digit numbers on the pattern <@lit="YYYYMMDD"> (ISO 8601 “basic” date format), which correspond to the day of the observation, or the first day of the observation period in case of a time-series frequency less than daily. 

Such a series can be helpful when using the <@xrf="join"> command. 

# $obsmajor access
Output: 	series 

Returns a series holding the “major” or low-frequency component of each observation. This means the year for annual, quarterly or monthly time series; the day for hourly data; or the individual in the case of panel data. If the data are cross-sectional the series returned is just a 1-based index of the observations. 

See also <@ref="$obsminor">, <@ref="$obsmicro">. 

# $obsmicro access
Output: 	series 

Applicable when the observations in the current dataset have a major:minor:micro structure, as in dated daily time series (year:month:day). Returns a series holding the micro or highest-frequency component of each observation (for example, the day). 

See also <@ref="$obsmajor">, <@ref="$obsminor">. 

# $obsminor access
Output: 	series 

Applicable when the observations in the current dataset have a major:minor structure, as in quarterly time series (year:quarter), monthly time series (year:month), hourly data (day:hour) and panel data (individual:period). Returns a series holding the minor or high-frequency component of each observation (for example, the month). 

In the case of dated daily data, <@lit="$obsminor"> gets the month of each observation. 

See also <@ref="$obsmajor">, <@ref="$obsmicro">. 

# $panelpd access
Output: 	integer 

Specific to panel data, returns the time-series periodicity (e.g. 4 for quarterly data). If the periodicity is not set in the active panel dataset, returns 1 in analogy to <@ref="$pd"> for cross-sectional or undated data. If the dataset is not a panel NA is returned. 

See also <@ref="$pd">, <@ref="$datatype">, <@xrf="setobs">. 

# $parnames access
Output: 	array of strings 

Following estimation of a single-equation model, returns an array of strings holding the names of the model's parameters. The number of names matches the number of elements in the <@ref="$coeff"> vector. 

For models specified via a list of regressors the result will be the same as that of 

<code>          
     varnames($xlist)
</code>

(see <@ref="varnames">), but <@lit="$parnames"> is more general; it also works for models with no regressor list (<@xrf="nls">, <@xrf="mle">, <@xrf="gmm">). 

# $pd access
Output: 	integer 

Returns the frequency or periodicity of the data (e.g. 4 for quarterly data). In the case of panel data the value returned is the total time-series length. 

See also <@ref="$panelpd">. 

# $pi access
Output: 	scalar 

Returns the value of π in double precision. 

# $pkgdir access
Output: 	string 

A special facility for use by authors of function packages. Returns an empty string unless a packaged function is executing, in which case it returns the full (platform dependent) path under which the package is installed. For instance the return value might be 

<code>          
     /usr/share/gretl/functions/foo
</code>

if that's the directory in which <@lit="foo.gfn"> is located. This enables package writers to access resources such as matrix files that they have included in their package. 

# $pvalue access
Output: 	scalar or matrix 

Returns the p-value of the test statistic that was generated by the last explicit hypothesis-testing command, if any (for example, <@lit="chow">). See chapter 10 of the <@pdf="Gretl User's Guide#chap:genr"> for details. 

In most cases the return value is a scalar but sometimes it is a matrix (for example, the trace and lambda-max p-values from the Johansen cointegration test); in that case the values in the matrix are laid out in the same pattern as the printed results. 

See also <@ref="$test">. 

# $qlrbreak access
Output: 	scalar 

Must follow an invocation of the <@xrf="qlrtest"> command (the QLR test for a structural break at an unknown point). The value returned is the 1-based index of the observation at which the test statistic is maximized. 

# $result access
Output: 	matrix or bundle 

Provides stored information following certain commands that do not have specific accessors. The commands in question include <@xrf="bds">, <@xrf="bkw">, <@xrf="corr">, <@xrf="fractint">, <@xrf="freq">, <@xrf="hurst">, <@xrf="leverage">, <@xrf="summary">, <@xrf="vif"> and <@xrf="xtab"> (in which cases the result is a matrix), plus <@xrf="pkg"> (which optionally stores a bundle result). 

# $rho access
Output: 	scalar 
Argument: 	<@var="n">  (scalar, optional)

Without arguments, returns the first-order autoregressive coefficient for the residuals of the last model. After estimating a model via the <@lit="ar"> command, the syntax <@lit="$rho(n)"> returns the corresponding estimate of ρ(<@mth="n">). 

# $rsq access
Output: 	scalar 

Returns the unadjusted <@mth="R"><@sup="2"> from the last estimated model, if available. 

# $sample access
Output: 	series 

Must follow estimation of a single-equation model. Returns a dummy series with value 1 for observations used in estimation, 0 for observations within the currently defined sample range but not used (presumably because of missing values), and NA for observations outside of the current range. 

If you wish to compute statistics based on the sample that was used for a given model, you can do, for example: 

<code>          
     ols y 0 xlist
     series sdum = $sample
     smpl sdum --dummy
</code>

# $sargan access
Output: 	row vector 

Must follow a <@lit="tsls"> command. Returns a 1×3 vector, containing the value of the Sargan over-identification test statistic, the corresponding degrees of freedom and p-value, in that order. If the model is exactly identified, the statistic is unavailable, and trying to access it provokes an error. 

# $seed access
Output: 	scalar 

Returns the value with which gretl's random number generator was seeded. If you set the seed yourself there's no need to use this accessor, but it may be of interest if the seed was set automatically (based on the time that execution of the program started). 

# $sigma access
Output: 	scalar or matrix 

Requires that a model has been estimated. If the last model was a single equation, returns the (scalar) Standard Error of the Regression (or in other words, the standard deviation of the residuals, with an appropriate degrees of freedom correction). If the last model was a system of equations, returns the cross-equation covariance matrix of the residuals. 

# $stderr access
Output: 	matrix or scalar 
Argument: 	<@var="s">  (name of coefficient, optional)

With no arguments, <@lit="$stderr"> returns a column vector containing the standard error of the coefficients for the last model. With the optional string argument it returns a scalar, namely the standard error of the parameter named <@var="s">. 

If the “model” in question is actually a system, the result depends on the characteristics of the system: for VARs and VECMs the value returned is a matrix with one column per equation, otherwise it is a column vector containing the coefficients from the first equation followed by those from the second equation, and so on. 

See also <@ref="$coeff">, <@ref="$vcv">. 

# $stopwatch access
Output: 	scalar 

Must be preceded by <@lit="set stopwatch">, which activates the measurement of CPU time. The first use of this accessor yields the seconds of CPU time that have elapsed since the <@lit="set stopwatch"> command. At each access the clock is reset, so subsequent uses of <@lit="$stopwatch"> yield the seconds of CPU time since the previous access. 

When a user-defined function is executing, the <@lit="set stopwatch"> command and <@lit="$stopwatch"> accessor are specific to that function—that is, timing within a function does not disrupt any “global” timing that may be going on in the main script. 

# $sysA access
Output: 	matrix 

Must follow estimation of a simultaneous equations system. Returns the matrix of coefficients on the lagged endogenous variables, if any, in the structural form of the system. See the <@xrf="system"> command. 

# $sysB access
Output: 	matrix 

Must follow estimation of a simultaneous equations system. Returns the matrix of coefficients on the exogenous variables in the structural form of the system. See the <@xrf="system"> command. 

# $sysGamma access
Output: 	matrix 

Must follow estimation of a simultaneous equations system. Returns the matrix of coefficients on the contemporaneous endogenous variables in the structural form of the system. See the <@xrf="system"> command. 

# $sysinfo access
Output: 	bundle 

Returns a bundle containing information on the capabilities of the gretl build and the system on which gretl is running. The members of the bundle are as follows: 

<indent>
• <@lit="mpi">: integer, equals 1 if the system supports MPI (Message Passing Interface), otherwise 0. 
</indent>

<indent>
• <@lit="omp">: integer, equals 1 if gretl is built with support for Open MP, otherwise 0. 
</indent>

<indent>
• <@lit="ncores">: integer, the number of physical processor cores available. 
</indent>

<indent>
• <@lit="nproc">: integer, the number of processors available, which will be greater than <@lit="ncores"> if hyper-threading is enabled. 
</indent>

<indent>
• <@lit="mpimax">: integer, the maximum number of MPI processes that can be run in parallel. This is zero if MPI is not supported, otherwise it equals the local <@lit="nproc"> value unless an MPI hosts file has been specified, in which case it is the sum of the number of processors or “slots” across all the machines referenced in that file. 
</indent>

<indent>
• <@lit="wordlen">: integer, either 32 or 64 for 32- and 64-bit systems respectively. 
</indent>

<indent>
• <@lit="os">: string representing the operating system, either <@lit="linux">, <@lit="macos">, <@lit="windows"> or <@lit="other">. Note that versions of gretl prior to 2021e gave the string <@lit="osx"> for the Mac operating system; a version-independent test for Mac is therefore <@lit="instring($sysinfo.os, "os")"> 
</indent>

<indent>
• <@lit="hostname">: the name of the host machine on which the current gretl process is running (with a fallback of <@lit="localhost"> in case the name cannot be determined). 
</indent>

<indent>
• <@lit="mem">: a 2-vector holding total physical memory and free or available memory, expressed in MB. This information may not be available on all systems but should be on Windows, macOS and Linux. 
</indent>

<indent>
• <@lit="foreign">: a sub-bundle containing 0/1 indicators for the presence on the host system of each of the “foreign” programs supported by gretl, under the keys <@lit="julia">, <@lit="octave">, <@lit="ox">, <@lit="python">, <@lit="Rbin">, <@lit="Rlib"> and <@lit="stata">. The two keys pertaining to R represent the R executable and shared library, respectively. 
</indent>

Note that individual elements in the bundle can be accessed using “dot” notation without any need to copy the whole bundle under a user-specified name. For example, 

<code>          
     if $sysinfo.os == "linux"
         # do something linux-specific
     endif
</code>

# $system access
Output: 	bundle 

Must follow estimation of a system of equations via one of the commands <@xrf="system">, <@xrf="var"> or <@xrf="vecm">; returns a bundle containing many items of data pertaining to the system. All the relevant regular system accessors are included: these are referenced by keys that are the same as the regular accessor names, minus the leading dollar sign. So for example the residuals appear under the key <@lit="uhat"> and the coefficients under <@lit="coeff">. (Exceptions are the keys <@lit="A">, <@lit="B">, and <@lit="Gamma">, which correspond to the regular dollar accessors sysA, sysB, and sysGamma.) The keys for additional information should hopefully be fairly self-explanatory. To see what's available you can get a copy of the bundle and print its content, as in 

<code>          
     var 4 y1 y2 y2
     bundle b = $system
     print b
</code>

A bundle obtained in this way can be passed as the final, optional argument to the functions <@ref="fevd"> and <@ref="irf">. 

# $T access
Output: 	integer 

Returns the number of observations used in estimating the last model. 

# $t1 access
Output: 	integer 

Returns the 1-based index of the first observation in the currently selected sample. 

# $t2 access
Output: 	integer 

Returns the 1-based index of the last observation in the currently selected sample. 

# $test access
Output: 	scalar or matrix 

Returns the value of the test statistic that was generated by the last explicit hypothesis-testing command, if any (e.g. <@lit="chow">). See chapter 10 of the <@pdf="Gretl User's Guide#chap:genr"> for details. 

In most cases the return value is a scalar but sometimes it is a matrix (for example, the trace and lambda-max statistics from the Johansen cointegration test); in that case the values in the matrix are laid out in the same pattern as the printed results. 

See also <@ref="$pvalue">. 

# $tmax access
Output: 	integer 

Returns the maximum legal setting for the end of the sample range via the <@xrf="smpl"> command. In most cases this will equal the number of observations in the dataset but within a hansl function the <@lit="$tmax"> value may be smaller, since in general data access within functions is limited to the sample range set by the caller. 

Note that <@lit="$tmax"> does not in general equal <@ref="$nobs">, which gives the number of observations in the current sample range. 

# $trsq access
Output: 	scalar 

Returns <@mth="TR"><@sup="2"> (sample size times R-squared) from the last model, if available. 

# $uhat access
Output: 	series 

Returns the residuals from the last model. This may have different meanings for different estimators. For example, after an ARMA estimation <@lit="$uhat"> will contain the one-step-ahead forecast error; after a probit model, it will contain the generalized residuals. 

If the “model” in question is actually a system (a VAR or VECM, or system of simultaneous equations), <@lit="$uhat"> retrieves the matrix of residuals, one column per equation. 

# $unit access
Output: 	series 

Valid for panel datasets only. Returns a series with value 1 for all observations on the first unit or group, 2 for observations on the second unit, and so on. 

# $vcv access
Output: 	matrix or scalar 
Arguments:	<@var="s1">  (name of coefficient, optional)
		<@var="s2">  (name of coefficient, optional)

With no arguments, <@lit="$vcv"> returns a square matrix containing the estimated covariance matrix for the coefficients of the last model. If the last model was a single equation, then you may supply the names of two parameters in parentheses to retrieve the estimated covariance between the parameters named <@var="s1"> and <@var="s2">. See also <@ref="$coeff">, <@ref="$stderr">. 

This accessor is not available for VARs or VECMs; for models of that sort see <@ref="$sigma"> and <@ref="$xtxinv">. 

# $vecGamma access
Output: 	matrix 

Must follow the estimation of a VECM; returns a matrix in which the Gamma matrices (coefficients on the lagged differences of the cointegrated variables) are stacked side by side. Each row represents an equation; for a VECM of lag order <@mth="p"> there are <@mth="p"> – 1 sub-matrices. 

# $version access
Output: 	scalar 

Returns an integer value that codes for the program version. The current gretl version string takes the form of a 4-digit year followed by a letter from a to j representing the sequence of releases within the year (for example, 2015d). The return value from this accessor is formed as 10 times the year plus the zero-based lexical order of the letter, so 2015d translates to 20153. 

Prior to gretl 2015d, version identifiers took the form x.y.z (three integers separated by dots), and in that case the accessor value was calculated as <@lit="10000*x + 100*y + z">, so that for example 1.10.2 (the last release under the old scheme) translates as 11002. Numerical order of <@lit="$version"> values is therefore preserved across the change in versioning scheme. 

# $vma access
Output: 	matrix 

Must follow the estimation of a VAR or a VECM; returns a matrix containing the VMA representation up to the order specified via the <@lit="set horizon"> command. See chapter 32 of the <@pdf="Gretl User's Guide#chap:var"> for details. 

# $windows access
Output: 	integer 

Returns 1 if gretl is running on MS Windows, otherwise 0. By conditioning on the value of this variable you can write shell calls that are portable across different operating systems. 

Also see the <@xrf="shell"> command. 

# $workdir access
Output: 	string 

This accessor returns the path which gretl reads from and writes to by default. A fuller discussion is provided in the Command Reference under <@xrf="workdir">. Note that this string can be set by the user via the <@xrf="set"> command. 

# $xlist access
Output: 	list 

If the last model was a single equation, returns the list of regressors. If the last model was a system of equations, returns the “global” list of exogenous variables (in the same order in which they appear in <@ref="$sysB">). If the last model was a VAR, returns the list of exogenous regressors, if any, except for standard deterministic terms (constant, trend, seasonals). 

# $xtxinv access
Output: 	matrix 

Following estimation of a VAR or VECM (only), returns <@mth="X'X"><@sup="-1">, where <@mth="X"> is the common matrix of regressors used in each of the equations. While this accessor is available for a VECM estimated with a restriction imposed on α (the “loadings” matrix), it should be borne in mind that in that case not all coefficients of the regressors are freely varying. 

# $yhat access
Output: 	series 

Returns the fitted values from the last regression. 

# $ylist access
Output: 	list 

If the last model estimated was a VAR, VECM or simultaneous system, returns the associated list of endogenous variables. If the last model was a single equation, this accessor gives a list with a single element, the dependent variable. In the special case of the biprobit model the list contains two elements. 

## Built-in strings

# $dotdir straccess
Output: 	string 

Yields the full path of the directory gretl uses for temporary files. To use it in string-substitution mode, prepend the at-sign (@dotdir). 

# $gnuplot straccess
Output: 	string 

Yields the path to the gnuplot executable. To use it in string-substitution mode, prepend the at-sign (@gnuplot). 

# $gretldir straccess
Output: 	string 

Yields the full path of the gretl installation directory. To use it in string-substitution mode, prepend the at-sign (@gretldir). 

# $tramo straccess
Output: 	string 

Yields the path to the tramo executable. To use it in string-substitution mode, prepend the at-sign (@tramo) 

# $tramodir straccess
Output: 	string 

Yields the path string of the tramo data directory. To use it in string-substitution mode, prepend the at-sign (@tramodir). 

# $x12a straccess
Output: 	string 

Yields the path to the x-12-arima executable. To use it in string-substitution mode, prepend the at-sign (@x12a). 

# $x12adir straccess
Output: 	string 

Yields the path of the x-12-arima data directory. To use it in string-substitution mode, prepend the at-sign (@x12adir). 

## Functions proper

# abs math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the absolute value of <@var="x">. 

# acos math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the arc cosine of <@var="x">, that is, the value whose cosine is <@var="x">. The result is in radians; the input should be in the range –1 to 1. 

# acosh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the inverse hyperbolic cosine of <@var="x"> (positive solution). <@var="x"> should be greater than 1; otherwise, NA is returned. See also <@ref="cosh">. 

# aggregate stats
Output: 	matrix 
Arguments:	<@var="x">  (series or list)
		<@var="byvar">  (series or list)
		<@var="funcname">  (string, optional)

In the most minimal usage, <@var="x"> is set to <@lit="null">, <@var="byvar"> is a single series and the third argument is omitted, or set to <@lit="null">. In this case, the return value is a matrix with two columns holding, respectively, the distinct values of <@var="byvar">, sorted in ascending order, and the count of observations at which <@var="byvar"> takes on each of these values. For example, 

<code>          
     open data4-1
     eval aggregate(null, bedrms)
</code>

will show that the series <@lit="bedrms"> has values 3 (with count 5) and 4 (with count 9). 

More generally, if <@var="byvar"> is a list with <@mth="n"> members, then the left-hand <@mth="n"> columns hold the combinations of the distinct values of each of the <@mth="n"> series and the count column holds the number of observations at which each combination is realized. Note that the count column can always be found at the position <@lit="nelem(byvar) + 1">. 

<@itl="Specifying an aggregation function"> 

If the third argument is given, then <@var="x"> must not be <@lit="null">, and the rightmost <@mth="m"> columns hold the values of the statistic specified by <@var="funcname"> for each of the variables in <@var="x">. (Thus, <@mth="m"> is equal to 1 if <@var="x"> is a single series and equal to <@lit="nelem(x)"> if <@var="x"> is a list.) The given statistic is calculated on the respective sub-samples defined by the combinations in <@var="byvar"> (in ascending order); these combinations are shown in the first <@mth="n"> column(s) of the returned matrix. 

So, in the special case where <@var="x"> and <@var="byvar"> are both individual series, the return value is a matrix with three columns holding, respectively, the distinct values of <@var="byvar">, sorted in ascending order; the count of observations at which <@var="byvar"> takes on each of these values; and the values of the statistic specified by <@var="funcname"> calculated on series <@var="x">, using only those observations at which <@var="byvar"> takes on the value given in the first column. 

The following values of <@var="funcname"> are supported “natively”: <@ref="sum">, <@ref="sumall">, <@ref="mean">, <@ref="sd">, <@ref="var">, <@ref="sst">, <@ref="skewness">, <@ref="kurtosis">, <@ref="min">, <@ref="max">, <@ref="median">, <@ref="nobs"> and <@ref="gini">. Each of these functions takes a series argument and returns a scalar value, and in that sense can be said to “aggregate” the series in some way. You may give the name of a user-defined function as the aggregator; like the built-ins, such a function must take a single series argument and return a scalar value. 

Note that although a count of cases is provided automatically the <@lit="nobs"> function is not redundant as an aggregator, since it gives the number of valid (non-missing) observations on <@var="x"> at each <@var="byvar"> combination. 

For a simple example, suppose that <@lit="region"> represents a coding of geographical region using integer values 1 to <@mth="n">, and <@lit="income"> represents household income. Then the following would produce an <@itl="n">×3 matrix holding the region codes, the count of observations in each region, and mean household income for each of the regions: 

<code>          
     matrix m = aggregate(income, region, mean)
</code>

For an example using lists, let <@lit="gender"> be a male/female dummy variable, let <@lit="race"> be a categorical variable with three values, and consider the following: 

<code>          
     list BY = gender race
     list X = income age
     matrix m = aggregate(X, BY, sd)
</code>

The <@lit="aggregate"> call here will produce a 6×5 matrix. The first two columns hold the 6 distinct combinations of gender and race values; the middle column holds the count for each of these combinations; and the rightmost two columns contain the sample standard deviations of <@lit="income"> and <@lit="age">. 

Note that if <@var="byvar"> is a list, some combinations of the <@var="byvar"> values may not be present in the data (giving a count of zero). In that case the value of the statistics for <@var="x"> are recorded as <@lit="NaN"> (not a number). If you want to ignore such cases you can use the <@ref="selifr"> function to select only those rows that have a non-zero count. The column to test is one place to the right of the number of <@var="byvar"> variables, so we can do: 

<code>          
     matrix m = aggregate(X, BY, sd)
     scalar c = nelem(BY)
     m = selifr(m, m[,c+1])
</code>

# argname strings
Output: 	string 
Arguments:	<@var="s">  (string)
		<@var="default">  (string, optional)

For <@var="s"> the name of a parameter to a user-defined function, returns the name of the corresponding argument, if the argument had a name at the caller level. If the argument was anonymous, an empty string is returned unless the optional <@var="default"> argument is provided, in which case its value is used as a fallback. 

# array data-utils
Output: 	see below 
Argument: 	<@var="n">  (integer)

The basic “constructor” function for a new array variable. In using this function you must specify a type (in plural form) for the array: <@lit="strings">, <@lit="matrices">, <@lit="bundles">, <@lit="lists"> or <@lit="arrays">. The return value is an array of the specified type with <@var="n"> elements, each of which is initialized as “empty” (e.g. zero-length string, null matrix). Examples of usage: 

<code>          
     strings S = array(5)
     matrices M = array(3)
</code>

See also <@ref="defarray">. 

# asin math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the arc sine of <@var="x">, that is, the value whose sine is <@var="x">. The result is in radians; the input should be in the range –1 to 1. 

# asinh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the inverse hyperbolic sine of <@var="x">. See also <@ref="sinh">. 

# assert programming
Output: 	scalar 
Argument: 	<@var="expr">  (scalar)

This function is intended for testing or debugging of hansl code. The argument should be an expression which evaluates to a scalar. The return value is 1 if <@var="expr"> evaluates to a non-zero value (boolean “true”, or “success”) or 0 if it evaluates to zero (boolean “false”, or “failure”). 

By default there are no consequences of a call to <@lit="assert"> failing other than the return value being zero. However, the <@xrf="set"> command can be used to make failure of an assertion more consequential. There are three levels: 

<code>          
     # print a warning message but continue execution
     set assert warn
     # print an error message and stop script execution
     set assert stop
     # print a message to stderr and abort the program
     set assert fatal
</code>

In most cases <@lit="stop"> is sufficient to terminate a script but in certain special cases (such as within a function called from a command block such as <@xrf="mle">) it may be necessary to use the <@lit="fatal"> setting to get a clear indication of the failing assertion. Note, however, that in this case the message will go to standard error output. 

The default behavior can be restored via 

<code>          
     set assert off
</code>

By way of a simple example, if at a certain point in a hansl script a scalar <@lit="x"> ought to be non-negative, the following will flag an error if that is not the case: 

<code>          
     set assert stop
     assert(x >= 0)
</code>

# atan math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the arc tangent of <@var="x">, that is, the value whose tangent is <@var="x">. The result is in radians. 

See also <@ref="tan">, <@ref="atan2">. 

# atan2 math
Output: 	same type as input 
Arguments:	<@var="y">  (scalar, series or matrix)
		<@var="x">  (scalar, series or matrix)

Returns the principal value of the arc tangent of <@var="y">/<@var="x">, using the signs of the two arguments to determine the quadrant of the result. The return value is in radians, in the range [–π, π]. 

If the two arguments differ in type, the type of the result is the “higher” of the two, where the ordering is matrix > series > scalar. For example, if <@var="y"> is a scalar and <@var="x"> an <@mth="n">-vector (or vice versa) the result is an <@mth="n">-vector. Note that matrix arguments must be vectors, and if neither argument is a scalar the two arguments must be of the same length. 

See also <@ref="tan">, <@ref="tanh">. 

# atanh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the inverse hyperbolic tangent of <@var="x">. See also <@ref="tanh">. 

# atof strings
Output: 	scalar 
Argument: 	<@var="s">  (string)

Closely related to the C library function of the same name. Returns the result of converting the string <@var="s"> (or the leading portion thereof, after discarding any initial white space) to a floating-point number. Unlike <@lit="atof"> in C, however, the decimal character is always assumed (for reasons of portability) to be “<@lit=".">”. Any characters that follow the portion of <@var="s"> that converts to a floating-point number under this assumption are ignored. 

If none of <@var="s"> (following any discarded white space) is convertible under the stated assumption, <@lit="NA"> is returned. 

<code>          
     # examples
     x = atof("1.234") # gives x = 1.234
     x = atof("1,234") # gives x = 1
     x = atof("1.2y")  # gives x = 1.2
     x = atof("y")     # gives x = NA
     x = atof(",234")  # gives x = NA
</code>

See also <@ref="sscanf"> for more flexible string to numeric conversion. 

# bcheck programming
Output: 	scalar 
Arguments:	<@var="target">  (reference to bundle)
		<@var="input">  (bundle)
		<@var="required-keys">  (array of strings, optional)

Primarily intended for use by writers of function packages. Here is the context in which <@lit="bcheck"> may be useful: you have a function which accepts a bundle argument whereby the caller can make various choices. Some elements of the bundle may have default values—so the caller is not obliged to make an explicit choice—while other elements may be required. You want to determine whether the argument you get is valid. 

To use <@lit="bcheck"> you construct a template bundle containing all the supported keys, with values that exemplify the type associated with each key, and pass this in pointer form as <@var="target">. For the second argument, <@var="input">, pass the bundle you get from the caller. This function then checks the following: 

<indent>
• Does <@var="input"> contain any keys not present in <@var="target">? If so, <@lit="bcheck"> returns a non-zero value, indicating that <@var="input"> is erroneous. 
</indent>

<indent>
• Does <@var="input"> contain under any given key an object whose type does not match that in <@var="target">? If so, a non-zero value is returned. 
</indent>

<indent>
• If some elements in <@var="target"> require input from the caller (so the value you supply is not actually a default, just a placeholder to indicate the required type), you should supply a third argument to <@lit="bcheck">: an array of strings holding the keys for which input is not optional. Then the return value will be non-zero if any required elements are missing from <@var="input">. 
</indent>

If no errors are detected on these points, any values supplied in <@var="input"> are copied to <@var="target"> (that is, defaults are replaced by valid selections on the caller's part). If errors are found a message will be printed indicating what is wrong with <@var="input">. 

To give a simple example, suppose your function's argument bundle supports a matrix <@lit="X"> (required), a scalar <@lit="z"> with default value 0, and a string <@lit="s"> with default value “<@lit="display">”. Then the following code fragment would be suitable for checking a bundle named <@lit="uservals"> supplied by the caller: 

<code>          
     bundle target = _(X={}, z=0, s="display")
     strings req = defarray("X")
     err = bcheck(&target, uservals, req)
     if err
        # react appropriately
     else
        # go ahead using the values in target
     endif
</code>

# bessel math
Output: 	same type as input 
Arguments:	<@var="type">  (character)
		<@var="v">  (scalar)
		<@var="x">  (scalar, series or matrix)

Computes one of the Bessel function variants for order <@var="v"> and argument <@var="x">. The return value is of the same type as <@var="x">. The specific function is selected by the first argument, which must be <@lit="J">, <@lit="Y">, <@lit="I">, or <@lit="K">. A good discussion of the Bessel functions can be found on Wikipedia; here we give a brief account. 

case <@lit="J">: Bessel function of the first kind. Resembles a damped sine wave. Defined for real <@var="v"> and <@var="x">, but if <@var="x"> is negative then <@var="v"> must be an integer. 

case <@lit="Y">: Bessel function of the second kind. Defined for real <@var="v"> and <@var="x"> but has a singularity at <@var="x"> = 0. 

case <@lit="I">: Modified Bessel function of the first kind. An exponentially growing function. Acceptable arguments are as for case <@lit="J">. 

case <@lit="K">: Modified Bessel function of the second kind. An exponentially decaying function. Diverges at <@var="x"> = 0 and is not defined for negative <@var="x">. Symmetric around <@var="v"> = 0. 

# BFGSmax numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="f">  (function call)
		<@var="g">  (function call, optional)

Numerical maximization via the method of Broyden, Fletcher, Goldfarb and Shanno. On input the vector <@var="b"> should hold the initial values of a set of parameters, and the argument <@var="f"> should specify a call to a function that calculates the (scalar) criterion to be maximized, given the current parameter values and any other relevant data. If the object is in fact minimization, this function should return the negative of the criterion. On successful completion, <@lit="BFGSmax"> returns the maximized value of the criterion, and <@var="b"> holds the parameter values which produce the maximum. 

The optional third argument provides a means of supplying analytical derivatives (otherwise the gradient is computed numerically). The gradient function call <@var="g"> must have as its first argument a predefined matrix that is of the correct size to contain the gradient, given in pointer form. It also must take the parameter vector as an argument (in pointer form or otherwise). Other arguments are optional. 

For more details and examples see chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. See also <@ref="BFGScmax">, <@ref="NRmax">, <@ref="fdjac">, <@ref="simann">. 

# BFGSmin numerical
Output: 	scalar 

An alias for <@ref="BFGSmax">; if called under this name the function acts as a minimizer. 

# BFGScmax numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="bounds">  (matrix)
		<@var="f">  (function call)
		<@var="g">  (function call, optional)

Constrained numerical maximization using L-BFGS-B (limited memory BFGS, see <@bib="Byrd, Lu, Nocedal and Zhu, 1995;byrd-etal95">). On input the vector <@var="b"> should hold the initial values of a set of parameters, <@var="bounds"> should hold bounds on the parameter values (see below), and <@var="f"> should specify a call to a function that calculates the (scalar) criterion to be maximized, given the current parameter values and any other relevant data. If the object is in fact minimization, this function should return the negative of the criterion. On successful completion, <@lit="BFGScmax"> returns the maximized value of the criterion, subject to the constraints in <@var="bounds">, and <@var="b"> holds the parameter values which produce the maximum. 

The <@var="bounds"> matrix must have 3 columns and as many rows as there are constrained elements in the parameter vector. The first element on a given row is the (1-based) index of the constrained parameter; the second and third are the lower and upper bounds, respectively. The values <@lit="-$huge"> and <@lit="$huge"> should be used to indicate that the parameter is unconstrained downward or upward, respectively. For example, the following is the way to specify that the second element of the parameter vector must be non-negative: 

<code>          
     matrix bounds = {2, 0, $huge}
</code>

The optional fourth argument provides a means of supplying analytical derivatives (otherwise the gradient is computed numerically). The gradient function call <@var="g"> must have as its first argument a predefined matrix that is of the correct size to contain the gradient, given in pointer form. It also must take the parameter vector as an argument (in pointer form or otherwise). Other arguments are optional. 

For more details and examples see chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. See also <@ref="BFGSmax">, <@ref="NRmax">, <@ref="fdjac">, <@ref="simann">. 

# BFGScmin numerical
Output: 	scalar 

An alias for <@ref="BFGScmax">; if called under this name the function acts as a minimizer. 

# bincoeff math
Output: 	same type as input 
Arguments:	<@var="n">  (scalar, series or matrix)
		<@var="k">  (scalar, series or matrix)

Returns the binomial coefficient, that is the number of ways in which <@var="k"> items can be chosen from <@var="n"> items without repetition, irrespective of ordering. This is also equal to the coefficient of the (<@mth="k">+1)-th term in the polynomial expansion of the binomial power <@mth="(1+x)^n">. 

For integer arguments the result is <@mth="n!/k!(n-k)!"> but the function also accepts noninteger arguments, and the formula above generalizes to Γ(<@mth="n">+1)/(Γ(<@mth="k">+1) × Γ(<@mth="n-k">+1)). 

When <@var="k"> > <@var="n"> or <@var="k"> < 0 no valid answer exists and an error is flagged. 

If the two arguments differ in type, the type of the result is the “higher” of the two, where the ordering is matrix > series > scalar. For example, if <@var="n"> is a scalar and <@var="k"> an <@mth="r">-vector (or vice versa) the result is an <@mth="r">-vector. Note that matrix arguments must be vectors, and if neither argument is a scalar the two arguments must be of the same length. 

See also <@ref="gammafun"> and <@ref="lngamma">. 

# bkfilt timeseries
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="f1">  (integer, optional)
		<@var="f2">  (integer, optional)
		<@var="k">  (integer, optional)

Returns the result from application of the Baxter–King bandpass filter to the series <@var="y">. The optional parameters <@var="f1"> and <@var="f2"> represent, respectively, the lower and upper bounds of the range of frequencies to extract, while <@var="k"> is the approximation order to be used. 

If these arguments are not supplied then the default values depend on the periodicity of the dataset. For yearly data the defaults for <@var="f1">, <@var="f2"> and <@var="k"> are 2, 8 and 3, respectively; for quarterly data, 6, 32 and 12; for monthly data, 18, 96 and 36. These values are chosen to match the most common choice among practitioners, that is to use this filter for extracting the “business cycle” frequency component; this, in turn, is commonly defined as being between 18 months and 8 years. The filter, per default choice, spans 3 years of data. 

If <@var="f2"> is greater than or equal to the number of available observations, then the “low-pass” version of the filter will be run and the resulting series should be taken as an estimate of the trend component, rather than the cycle. See also <@ref="bwfilt">, <@ref="hpfilt">. 

# bkw stats
Output: 	matrix 
Arguments:	<@var="V">  (matrix)
		<@var="parnames">  (array of strings, optional)
		<@var="verbose">  (boolean, optional)

Computes BKW collinearity diagnostics (see <@bib="Belsley, Kuh and Welsch (1980);belsley-etal80">) given a covariance matrix of parameter estimates, <@var="V">. The optional second argument, which can be an array of strings or a string containing comma-separated names, is used to label the columns showing the variance proportions; the number of names should match the dimension of <@var="V">. After estimation of a model in gretl, suitable arguments can be obtained via the <@ref="$vcv"> and <@ref="$parnames"> accessors. 

By default this function operates silently, just returning the BKW table as a matrix, but if a non-zero value is given for the third argument the table is printed along with some analysis. 

There is also a command form of this facility, <@xrf="bkw">, which automatically references the last model and requires no arguments. 

# boxcox transforms
Output: 	same type as input 
Arguments:	<@var="y">  (series or matrix)
		<@var="d">  (scalar)

Returns the Box–Cox transformation with parameter <@var="d"> for the positive series <@var="y"> (or the columns of matrix <@var="y">). 

The result is (<@mth="y"><@sup="d"> - 1)/<@mth="d"> for <@mth="d"> not equal to zero, or log(<@mth="y">) for <@mth="d"> = 0. 

# bread data-utils
Output: 	bundle 
Arguments:	<@var="fname">  (string)
		<@var="import">  (boolean, optional)

Reads a bundle from the file specified by the <@var="fname"> argument. By default the bundle is assumed to be represented in XML, and to be gzip-compressed if <@var="fname"> has extension <@lit=".gz">. But if the extension is <@lit=".json"> or <@lit=".geojson"> the content is assumed to be JSON. 

In the XML case the file must contain a <@lit="gretl-bundle"> element, which is used to store zero or more <@lit="bundled-item"> elements. For example, 

<code>          
     <?xml version="1.0" encoding="UTF-8"?>
     <gretl-bundle name="temp">
          <bundled-item key="s" type="string">moo</bundled-item>
          <bundled-item key="x" type="scalar">3</bundled-item>
     </gretl-bundle>
</code>

As you might expect, files suitable for reading via <@lit="bread"> are generated by the companion function <@ref="bwrite">. 

If the file name does not contain a full path specification, it will be looked for in several “likely” locations, beginning with the currently set <@xrf="workdir">. However, if a non-zero value is given for the optional <@var="import"> argument, the input file is taken to be in the user's “dot” directory. In that case <@var="fname"> should be a plain file name, without any path component. 

Should an error occur (such as the file being badly formatted or inaccessible), an error is returned via the <@ref="$error"> accessor. 

See also <@ref="mread">, <@ref="bwrite">. 

# brename data-utils
Output: 	scalar 
Arguments:	<@var="B">  (bundle)
		<@var="oldkey">  (string)
		<@var="newkey">  (string)

If the bundle <@var="B"> contains a member under the key <@var="oldkey">, its key is changed to <@var="newkey">, otherwise an error is flagged. Returns 0 on successful renaming. 

Changing the key of a bundle member is not a common task but it can arise in the context of functions that work with bundles, and <@lit="brename"> is an efficient tool for the job. Example: 

<code>          
     # set up a bundle holding a big matrix
     bundle b
     b.X = mnormal(1000, 1000)
     if 0
         # change the key manually
         Xcopy = b.X
         delete b.X
         b.Y = Xcopy
         delete Xcopy
     else
         # versus: change it efficiently
         brename(b, "X", "Y")
     endif
</code>

The first method requires that the big matrix be copied twice, out of the bundle then back into it under a different key; the efficient method changes the key directly. 

# bwfilt timeseries
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="n">  (integer)
		<@var="omega">  (scalar)

Returns the result from application of a low-pass Butterworth filter with order <@var="n"> and frequency cutoff <@var="omega"> to the series <@var="y">. The cutoff is expressed in degrees and must be greater than 0 and less than 180. Smaller cutoff values restrict the pass-band to lower frequencies and hence produce a smoother trend. Higher values of <@var="n"> produce a sharper cutoff, at the cost of possible numerical instability. 

Inspecting the periodogram of the target series is a useful preliminary when you wish to apply this function. See chapter 30 of the <@pdf="Gretl User's Guide#chap:tsfilter"> for details. See also <@ref="bkfilt">, <@ref="hpfilt">. 

# bwrite data-utils
Output: 	integer 
Arguments:	<@var="B">  (bundle)
		<@var="fname">  (string)
		<@var="export">  (boolean, optional)

Writes the bundle <@var="B"> to file, serialized in XML or, if <@var="fname"> has extension <@lit=".json"> or <@lit=".geojson">, as JSON. See <@ref="bread"> for a description of the format when XML is used. If <@var="fname"> already exists, it will be overwritten. The nominal return value is 0 on successful completion; if writing fails an error is flagged. 

The output file will be written in the currently set <@xrf="workdir">, unless <@var="fname"> contains a full path specification. However, if a non-zero value is given for the <@var="export"> argument, the file will be written into the user's “dot” directory. In that case a plain file name, without any path component, should be given for the second argument. 

In the case of XML output (only), the option of gzip compression is available; this is applied if <@var="fname"> has the extension <@lit=".gz">. 

See also <@ref="bread">, <@ref="mwrite">. 

# carg complex
Output: 	matrix 
Argument: 	<@var="C">  (complex matrix)

Returns an <@itl="m">×<@itl="n"> real matrix holding the complex “argument” of each element of the <@itl="m">×<@itl="n"> complex matrix <@var="C">. The argument of the complex number <@mth="z"> = <@mth="x"> + <@mth="yi"> can also be computed as <@lit="atan2(y, x)">. 

See also <@ref="abs">, <@ref="cmod">, <@ref="atan2">. 

# cdemean transforms
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="standardize">  (boolean, optional)

Centers the columns of matrix <@var="X"> around their means. If the optional second argument has a non-zero value then in addition the centered values are divided by the column standard deviations (which are calculated using <@mth="n"> – 1 as divisor, where <@mth="n"> is the number of rows of <@var="X">). 

Note that <@ref="stdize"> provides more flexible functionality. 

# cdf probdist
Output: 	same type as input 
Arguments:	<@var="d">  (string)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="p1 = cdf(N, -2.5)">
		<@lit="p2 = cdf(X, 3, 5.67)">
		<@lit="p3 = cdf(D, 0.25, -1, 1)">

Cumulative distribution function calculator. Returns <@mth="P(X ≤ x)">, where the distribution of <@mth="X"> is determined by the string <@var="d">. Between the arguments <@var="d"> and <@var="x">, zero or more additional scalar arguments are required to specify the parameters of the distribution, as follows (but note that the normal distribution has its own convenience function, <@ref="cnorm">). 

<indent>
• Standard normal (d = z, n, or N): no extra arguments 
</indent>

<indent>
• Bivariate normal (D): correlation coefficient 
</indent>

<indent>
• Logistic (lgt or s): no extra arguments 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Gamma (g or G): shape; scale 
</indent>

<indent>
• Beta (beta): 2 shape parameters 
</indent>

<indent>
• Binomial (b or B): probability; number of trials 
</indent>

<indent>
• Poisson (p or P): mean 
</indent>

<indent>
• Exponential (exp): scale 
</indent>

<indent>
• Weibull (w or W): shape; scale 
</indent>

<indent>
• Laplace (l or L): mean; scale 
</indent>

<indent>
• Generalized Error (E): shape 
</indent>

<indent>
• Non-central chi square (ncX): df, non-centrality parameter 
</indent>

<indent>
• Non-central F (ncF): df (num.), df (den.), non-centrality parameter 
</indent>

<indent>
• Non-central t (nct): df, non-centrality parameter 
</indent>

Note that most cases have aliases to help memorizing the codes. The bivariate normal case is special: the syntax is <@lit="x = cdf(D, rho, z1, z2)"> where <@lit="rho"> is the correlation between the variables <@lit="z1"> and <@lit="z2">. 

See also <@ref="pdf">, <@ref="critical">, <@ref="invcdf">, <@ref="pvalue">. 

# cdiv complex
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="Y">  (matrix)

This is a legacy function, predating gretl's native support for complex matrices. 

Complex division. The two arguments must have the same number of rows, <@mth="n">, and either one or two columns. The first column contains the real part and the second (if present) the imaginary part. The return value is an <@itl="n">×2 matrix or, if the result has no imaginary part, an <@mth="n">-vector. See also <@ref="cmult">. 

# cdummify transforms
Output: 	list 
Argument: 	<@var="L">  (list)

This function returns a list in which each series in <@var="L"> that has the “coded” attribute is replaced by a set of dummy variables representing each of its coded values, with the least value omitted. If <@var="L"> contains no coded series the return value will be identical to <@var="L">. 

The generated dummy variables, if any, are named on the pattern <@lit="D"><@var="varname"><@lit="_"><@var="vi"> where <@var="vi"> is the <@var="i"><@sup="th"> represented value of the coded variable. In case any values are negative, “m” is inserted before the (absolute) value of <@var="vi">. 

For example, suppose <@var="L"> contains a coded series named <@lit="C1"> with values –9, –7, 0, 1 and 2. Then the generated dummies will be <@lit="DC1_m7"> (coding for C1 = –7), <@lit="DC1_0"> (coding for C1 = 0), and so on. 

See also <@ref="dummify">, <@ref="getinfo">. 

# ceil math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Ceiling function: returns the smallest integer greater than or equal to <@var="x">. See also <@ref="floor">, <@ref="int">. 

# cholesky linalg
Output: 	square matrix 
Argument: 	<@var="A">  (positive definite matrix)

Performs a Cholesky decomposition of <@var="A">. If <@var="A"> is real it must be symmetric and positive definite; if so, the result is a lower-triangular matrix <@mth="L"> which satisfies <@mth="A = LL'">. If <@var="A"> is complex it must be Hermitian and positive definite, and the result is a lower-triangular complex matrix such that <@mth="A = LL^H">. Otherwise, the function will return an error. 

For the real case, see also <@ref="psdroot"> and <@ref="Lsolve">. 

# chowlin timeseries
Output: 	matrix 
Arguments:	<@var="Y">  (matrix)
		<@var="xfac">  (integer)
		<@var="X">  (matrix, optional)

We no longer recommend use of this function; please use <@ref="tdisagg"> instead. 

Expands the input data, <@var="Y">, to a higher frequency, using the method of <@bib="Chow and Lin (1971);chowlin71">. It is assumed that the columns of <@var="Y"> represent data series; the returned matrix has as many columns as <@var="Y"> and <@var="xfac"> times as many rows. It is also assumed that each low-frequency value should be treated as the average of <@var="xfac"> high-frequency values. 

The <@var="xfac"> value should be 3 for quarterly to monthly, 4 for annual to quarterly or 12 for annual to monthly. The optional third argument may be used to provide a matrix of covariates at the higher (target) frequency. 

The regressors used by default are a constant and trend. If <@var="X"> is provided, its columns are used as additional regressors; it is an error if the number of rows in <@var="X"> does not equal <@var="xfac"> times the number of rows in <@var="Y">. 

# cmod complex
Output: 	matrix 
Argument: 	<@var="C">  (complex matrix)

Returns an <@itl="m">×<@itl="n"> real matrix holding the complex modulus of each element of the <@itl="m">×<@itl="n"> complex matrix <@var="C">. The modulus of the complex number <@mth="z"> = <@mth="x"> + <@mth="yi"> equals the square root of <@mth="x"><@sup="2"> + <@mth="y"><@sup="2">. 

See also <@ref="abs">, <@ref="carg">. 

# cmult complex
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="Y">  (matrix)

This is a legacy function, predating gretl's native support for complex matrices. 

Complex multiplication. The two arguments must have the same number of rows, <@mth="n">, and either one or two columns. The first column contains the real part and the second (if present) the imaginary part. The return value is an <@itl="n">×2 matrix, or, if the result has no imaginary part, an <@mth="n">-vector. See also <@ref="cdiv">. 

# cnorm probdist
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the cumulative distribution function for a standard normal. See also <@ref="dnorm">, <@ref="qnorm">. 

# cnumber linalg
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the condition number of the <@itl="n">×<@itl="k"> matrix <@var="X">, as defined in <@bib="Belsley, Kuh and Welsch (1980);belsley-etal80">. If the columns of <@var="X"> are mutually orthogonal the condition number of <@var="X"> is unity. Conversely, a large value of the condition number is an indicator of multicollinearity; “large” is often taken to mean 50 or greater (sometimes 30 or greater). 

The steps in the calculation are: (1) form a matrix <@mth="Z"> whose columns are the columns of <@var="X"> divided by their respective Euclidean norms; (2) form <@mth="Z'Z"> and obtain its eigenvalues; and (3) compute the square root of the ratio of the largest to the smallest eigenvalue. 

See also <@ref="rcond">. 

# cnameget strings
Output: 	string or array of strings 
Arguments:	<@var="M">  (matrix)
		<@var="col">  (integer, optional)

If the <@var="col"> argument is given, retrieves the name for column <@var="col"> of matrix <@var="M">. If <@var="M"> has no column names attached the value returned is an empty string; if <@var="col"> is out of bounds for the given matrix an error is flagged. 

If no second argument is given, retrieves an array of strings holding the column names from <@var="M">, or an empty array if <@var="M"> does not have column names attached. 

Example: 

<code>          
     matrix A = { 11, 23, 13 ; 54, 15, 46 }
     cnameset(A, "Col_A Col_B Col_C")
     string name = cnameget(A, 3)
     print name
</code>

See also <@ref="cnameset">. 

# cnameset matrix
Output: 	scalar 
Arguments:	<@var="M">  (matrix)
		<@var="S">  (array of strings or list)

Attaches names to the columns of the <@itl="T">×<@itl="k"> matrix <@var="M">. If <@var="S"> is a named list, the names are taken from the names of the listed series; the list must have <@mth="k"> members. If <@var="S"> is an array of strings, it should contain <@mth="k"> elements. A single string is also acceptable as the second argument; in that case it should contain <@mth="k"> space-separated substrings. 

The nominal return value is 0 on successful completion; in case of failure an error is flagged. See also <@ref="rnameset">. 

Example: 

<code>          
     matrix M = {1, 2; 2, 1; 4, 1}
     strings S = array(2)
     S[1] = "Col1"
     S[2] = "Col2"
     cnameset(M, S)
     print M
</code>

# cols matrix
Output: 	integer 
Argument: 	<@var="X">  (matrix)

Returns the number of columns of <@var="X">. See also <@ref="mshape">, <@ref="rows">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# commute linalg
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="m">  (integer)
		<@var="n">  (integer, optional)
		<@var="post">  (integer, optional)
		<@var="add_id">  (integer, optional)

Returns the matrix <@var="A"> premultiplied by the commutation matrix <@mth="K"><@sub="m,n"> (more efficient than explicit multiplication). Each column of <@var="A"> is assumed to come from a vec operation on a <@mth="m x n"> matrix. In particular, 

<code>          
     commute(vec(B), rows(B), cols(B))
</code>

gives vec(<@mth="B'">). In order to compute the commutation matrix proper, just apply the function to an appropriately sized identity matrix. For example: 

<code>          
     K_32 = commute(I(6), 3, 2)
</code>

The optional argument <@var="n"> defaults to <@var="m">. If the optional argument <@var="post"> is non-zero, then post-multiplication is performed instead of pre-multiplication; the optional Boolean switch <@var="add_id"> will premultiply <@var="A"> by <@mth="I + K"><@sub="m,n"> instead of <@mth="K"><@sub="m,n">. 

# complex complex
Output: 	complex matrix 
Arguments:	<@var="A">  (scalar or matrix)
		<@var="B">  (scalar or matrix, optional)

Returns a complex matrix, where <@var="A"> is taken to supply the real part and <@var="B"> the imaginary part. If <@var="A"> is <@itl="m">×<@itl="n"> and <@var="B"> is a scalar the result is <@itl="m">×<@itl="n"> with a constant imaginary part—and similarly in the converse case but with a constant real part. If both arguments are matrices they must be of the same dimensions. If the second argument is omitted the imaginary part defaults to zero. See also <@ref="cswitch">. 

# conj complex
Output: 	complex matrix 
Argument: 	<@var="C">  (complex matrix)

Returns an <@itl="m">×<@itl="n"> complex matrix holding the complex conjugate of each element of the <@itl="m">×<@itl="n"> complex matrix <@var="C">. The conjugate of the complex number <@mth="z"> = <@mth="x"> + <@mth="yi"> equals <@mth="x"> – <@mth="yi">. 

See also <@ref="carg">, <@ref="abs">. 

# contains data-utils
Output: 	same type as input 
Arguments:	<@var="x">  (scalar, series or matrix)
		<@var="S">  (matrix)

Provides a means of determining whether the numerical object <@var="x"> contains any of the elements of <@var="S">, a matrix which plays the role of a set. 

The return value is an object of the same size as <@var="x"> containing 1s in positions where a value of <@var="x"> matches any element of <@var="S"> and zeros elsewhere. For example, the code 

<code>          
     matrix A = mshape(seq(1,9), 3, 3)
     matrix C = contains(A, {1, 5, 9})
</code>

gives 

<code>          
     A (3 x 3)

     1   4   7
     2   5   8
     3   6   9

     C (3 x 3)

     1   0   0
     0   1   0
     0   0   1
</code>

This function may be particularly useful when <@var="x"> is a series that contains a fine-grained encoding for a qualitative characteristic, and you wish to reduce this to a smaller number of categories. You can pack into <@var="S"> a set of values to be consolidated, and obtain a dummy variable with value 1 for observations matching this set, 0 otherwise. 

Since <@var="S"> serves as a set, for greatest efficiency it should be a vector with no repeated values, however an arbitrary matrix is accepted. 

# conv2d linalg
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="B">  (matrix)

Computes the 2-dimensional convolution of the matrices <@var="A"> and <@var="B">. If <@var="A"> is <@itl="r">×<@itl="c"> and <@var="B"> is <@itl="m">×<@itl="n"> then the returned matrix will have <@mth="r+m-1"> rows and <@mth="c+n-1"> columns. 

See also <@ref="fft">, <@ref="filter">. 

# cquad complex
Output: 	matrix 
Argument: 	<@var="Z">  (matrix)

Given an <@itl="m">×<@itl="n"> complex matrix <@var="Z">, returns an <@itl="m">×<@itl="n"> real matrix holding the quadrance of the elements of <@var="Z">. The quadrance of the complex number <@mth="z"> = <@mth="a"> + <@mth="bi"> is <@mth="a"><@sup="2"> + <@mth="b"><@sup="2">. It therefore equals the squared modulus of <@mth="z"> and also equals <@mth="z"> multiplied by its complex conjugate, but the direct calculation carried out by <@lit="cquad"> is considerably faster than either of the alternative approaches. 

# corr stats
Output: 	scalar 
Arguments:	<@var="y1">  (series or vector)
		<@var="y2">  (series or vector)

Computes the correlation coefficient between <@var="y1"> and <@var="y2">. The arguments should be either two series, or two vectors of the same length. See also <@ref="cov">, <@ref="mcov">, <@ref="mcorr">, <@ref="npcorr">. 

# corrgm timeseries
Output: 	matrix 
Arguments:	<@var="x">  (series, matrix or list)
		<@var="p">  (integer)
		<@var="y">  (series or vector, optional)

If only the first two arguments are given, computes the correlogram for <@var="x"> for lags 1 to <@var="p">. Let <@mth="k"> represent the number of elements in <@var="x"> (1 if <@var="x"> is a series, the number of columns if <@var="x"> is a matrix, or the number of list-members if <@var="x"> is a list). The return value is a matrix with <@var="p"> rows and 2<@mth="k"> columns, the first <@mth="k"> columns holding the respective autocorrelations and the remainder the respective partial autocorrelations. 

If a third argument is given, this function computes the cross-correlogram for each of the <@mth="k"> elements in <@var="x"> and <@var="y">, from lead <@var="p"> to lag <@var="p">. The returned matrix has 2<@mth="p"> + 1 rows and <@mth="k"> columns. If <@var="x"> is series or list and <@var="y"> is a vector, the vector must have just as many rows as there are observations in the current sample range. 

# cos math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the cosine of <@var="x">. See also <@ref="sin">, <@ref="tan">, <@ref="atan">. 

# cosh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the hyperbolic cosine of <@var="x">. 

See also <@ref="acosh">, <@ref="sinh">, <@ref="tanh">. 

# cov stats
Output: 	scalar 
Arguments:	<@var="y1">  (series or vector)
		<@var="y2">  (series or vector)

Returns the covariance between <@var="y1"> and <@var="y2">. The arguments should be either two series, or two vectors of the same length. See also <@ref="corr">, <@ref="mcov">, <@ref="mcorr">. 

# critical probdist
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="p">  (scalar, series or matrix)
Examples: 	<@lit="c1 = critical(t, 20, 0.025)">
		<@lit="c2 = critical(F, 4, 48, 0.05)">

Critical value calculator. Returns <@mth="x"> such that <@mth="P(X > x) = p">, where the distribution <@mth="X"> is determined by the character <@var="c">. Between the arguments <@var="c"> and <@var="p">, zero or more additional scalar arguments are required to specify the parameters of the distribution, as follows. 

<indent>
• Standard normal (c = z, n, or N): no extra arguments 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Binomial (b or B): probability; trials 
</indent>

<indent>
• Poisson (p or P): mean 
</indent>

<indent>
• Laplace (l or L): mean; scale 
</indent>

<indent>
• Standardized GED (E): shape 
</indent>

See also <@ref="cdf">, <@ref="invcdf">, <@ref="pvalue">. 

# cswitch complex
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="mode">  (scalar)

Reinterprets a real matrix as holding complex values or vice versa. The precise action depends on <@var="mode"> (which must have value 1, 2, 3 or 4) as follows: 

mode 1: <@var="A"> must be a real matrix with an even number of columns. Returns a complex matrix with half as many columns, the odd-numbered columns of <@var="A"> supplying the real parts and the even-numbered columns the imaginary parts. 

mode 2: Performs the inverse operation of mode 1. <@var="A"> must be a complex matrix and the return value is a real matrix with twice as many columns as <@var="A">. 

mode 3: <@var="A"> must be a real matrix with an even number of rows. Returns a complex matrix with half as many rows, the odd-numbered rows of <@var="A"> supplying the real parts and the even-numbered rows the imaginary parts. 

mode 4: Performs the inverse operation of mode 3. <@var="A"> must be a complex matrix and the return value is a real matrix with twice as many rows as <@var="A">. 

See also <@ref="complex">. 

# ctrans complex
Output: 	complex matrix 
Argument: 	<@var="C">  (complex matrix)

Returns an <@itl="n">×<@itl="m"> complex matrix holding the conjugate transpose of the <@itl="m">×<@itl="n"> complex matrix <@var="C">. The <@lit="'"> (prime) operator also performs conjugate transposition for complex matrices. The <@ref="transp"> function can be used on complex matrices but it performs “straight” transposition (not conjugated). 

# cum transforms
Output: 	same type as input 
Argument: 	<@var="x">  (series or matrix)

Cumulates <@var="x"> (that is, creates a running sum). When <@var="x"> is a series, produces a series <@mth="y"> each of whose elements is the sum of the values of <@var="x"> to date; the starting point of the summation is the first non-missing observation in the currently selected sample. When <@var="x"> is a matrix, its elements are cumulated by columns. 

See also <@ref="diff">. 

# curl data-utils
Output: 	integer 
Argument: 	<@var="&b">  (reference to bundle)

Provides a somewhat flexible means of obtaining a text buffer containing data from an internet server, using libcurl. On input the bundle <@var="b"> must contain a string named <@lit="URL"> which gives the full address of the resource on the target host. Other optional elements are as follows. 

<indent>
• “<@lit="header">”: a string specifying an HTTP header to be sent to the host. 
</indent>

<indent>
• “<@lit="postdata">”: a string holding data to be sent to the host. 
</indent>

The <@lit="header"> and <@lit="postdata"> fields are intended for use with an HTTP <@lit="POST"> request; if <@lit="postdata"> is present the <@lit="POST"> method is implicit, otherwise the <@lit="GET"> method is implicit. (But note that for straightforward <@lit="GET"> requests <@ref="readfile"> offers a simpler interface.) 

One other optional bundle element is recognized: if a scalar named <@lit="include"> is present and has a non-zero value, this is taken as a request to include the header received from the host with the output body. 

On completion of the request, the text received from the server is added to the bundle under the key “<@lit="output">”. 

If an error occurs in formulating the request (for example there's no <@lit="URL"> on input) the function fails, otherwise it returns 0 if the request succeeds or non-zero if it fails, in which case the error message from the curl library is added to the bundle under the key “<@lit="errmsg">”. Note, however, that “success” in this sense does not necessarily mean you got the data you wanted; all it means is that some response was received from the server. You must check the content of the output buffer (which may in fact be a message such as “Page not found”). 

Here is an example of use: downloading some data from the US Bureau of Labor Statistics site, which requires sending a JSON query. Note the use of <@ref="sprintf"> to embed double-quotes in the <@lit="POST"> data. 

<code>          
     bundle req
     req.URL = "http://api.bls.gov/publicAPI/v1/timeseries/data/"
     req.include = 1
     req.header = "Content-Type: application/json"
     string s = sprintf("{\"seriesid\":[\"LEU0254555900\"]}")
     req.postdata = s
     err = curl(&req)
     if err == 0
         s = req.output
         string line
         loop while getline(s, &line)
             printf "%s\n", line
         endloop
     endif
</code>

See also the functions <@ref="jsonget"> and <@ref="xmlget"> for means of processing JSON and XML data received, respectively. 

# dayspan calendar
Output: 	integer 
Arguments:	<@var="ed1">  (integer)
		<@var="ed2">  (integer)
		<@var="weeklen">  (integer)

Returns the number of (relevant) days between the epoch days <@var="ed1"> and <@var="ed2">, inclusive. The <@var="weeklen">, which must equal 5, 6 or 7, gives the number of days in the week that should be counted (a value of 6 omits Sundays, and a value of 5 omits both Saturdays and Sundays). 

To obtain epoch days from the more familiar form of dates, see <@ref="epochday">. Related: see <@ref="smplspan">. 

# defarray data-utils
Output: 	see below 
Argument: 	... (see below)

Enables the definition of an array variable <@itl="in extenso">, by providing one or more elements. In using this function you must specify a type (in plural form) for the array: <@lit="strings">, <@lit="matrices">, <@lit="bundles"> or <@lit="lists">. Each of the arguments must evaluate to an object of the specified type. On successful completion, the return value is an array of <@mth="n"> elements, where <@mth="n"> is the number of arguments. 

<code>          
     strings S = defarray("foo", "bar", "baz")
     matrices M = defarray(I(3), X'X, A*B, P[1:])
</code>

See also <@ref="array">. 

# defbundle data-utils
Output: 	bundle 
Argument: 	... (see below)

Enables the initialization of a bundle variable <@itl="in extenso">, by providing zero or more pairs of the form <@var="key">, <@var="member">. If we count the arguments from 1, every odd-numbered argument must evaluate to a string (key) and every even-numbered argument must evaluate to an object of a type that can be included in a bundle. 

A couple of simple examples: 

<code>          
     bundle b1 = defbundle("s", "Sample string", "m", I(3))
     bundle b2 = defbundle("yn", normal(), "x", 5)
</code>

The first example creates a bundle with members a string and a matrix; the second, a bundle with a series member and a scalar member. Note that you cannot specify a type for each argument when using this function, so you must accept the “natural” type of the argument in question. If you wanted to add a series with constant value 5 to a bundle named <@lit="b1"> it would be necessary to do something like the following (after declaring <@lit="b1">): 

<code>          
     series b1.s5 = 5
</code>

If no arguments are given to this function it is equivalent to creating an empty bundle (or to emptying an existing bundle of its content), as could also be done via 

<code>          
     bundle b = null
</code>

<@itl="Variant syntax"> 

Two alternative forms of syntax are available for defining bundles. In each case the keyword <@lit="defbundle"> is replaced by a single underscore. In the first variant the comma-separated arguments take the form <@lit="key=value">, where the key is taken to be a literal string and does not require quotation. Here is an example: 

<code>          
     bundle b = _(x=5, strval="some string", m=I(3))
</code>

This form is particularly convenient for constructing an anonymous bundle on the fly as a function argument, as in 

<code>          
     b = regls(ys, LX, _(lfrac=0.35, stdize=0))
</code>

where the <@lit="regls"> function takes an optional bundle argument holding various parameters. 

The second variant is designed for the case where you wish to pack several pre-existing named objects into a bundle: you just give their names, unquoted: 

<code>          
     bundle b = _(x, y, z)
</code>

Here the object <@lit="x"> is copied into the bundle under the key “<@lit="x">”, and similarly for <@lit="y"> and <@lit="z">. 

These alternative forms involve less typing than the full <@lit="defbundle()"> version and are likely to be more convenient in many cases, but note that they are less flexible. Only the full version can handle keys given as string variables rather than literal strings. 

# deflist data-utils
Output: 	list 
Argument: 	... (see below)

Defines a list (of named series), given one or more suitable arguments. Each argument must be a named series (given by name or integer ID number), an existing named list, or an expression which evaluates to a list (including a vector which can be interpreted as a set of series ID numbers). 

One point to note: this function simply concatenates its arguments to produce the list that it returns. If the intent is that the return value does not contain duplicates (does not reference any given series more than once), it is up to the caller to ensure that requirement is satisfied. 

# deseas timeseries
Output: 	series 
Arguments:	<@var="x">  (series)
		<@var="opts">  (bundle, optional)

The primary purpose of this function is to produce a deseasonalized version of the (quarterly or monthly) input series <@var="x">, using X-13ARIMA-SEATS; it is available only if X-13ARIMA-SEATS is installed. If the second, optional argument is omitted, seasonal adjustment is carried out with all X-13ARIMA options at their default values (fully automatic procedure). When <@var="opts"> is supplied, it may contain any of the following option specifications. 

<indent>
• <@lit="verbose">: what to print? 0 = nothing (the default); 1 = confirmation of the options selected; 2 = confirmation of options plus the output from X-13ARIMA. 
</indent>

<indent>
• <@lit="seats">: 1 to use the SEATS algorithm in place of the default X11 algorithm for seasonal adjustment, or 0. 
</indent>

<indent>
• <@lit="airline">: 1 to use the “airline” ARIMA model specification (0,1,1)(0,1,1) in place of the default automatic model selection, or 0. 
</indent>

<indent>
• <@lit="arima">: can be used to impose a chosen ARIMA specification, in the form of a 6-vector holding small non-negative integers. These are given the (p,d,q,P,D,Q) interpretation, in traditional time-series notation: the first three terms represent the non-seasonal AR, Integration and MA orders, and the last three the seasonal counterparts. If both <@lit="airline"> and <@lit="arima"> are given, <@lit="arima"> takes precedence. 
</indent>

<indent>
• <@lit="outliers">: enable detection and correction for outliers (choices 1 through 7), or 0 (the default) to omit this feature. The three available outlier types with their numerical codes are: 1 = additive outlier (ao), 2 = level shift (ls), 4 = temporary change (tc). To combine options you add the codes, for example 1 + 2 + 4 = 7 to activate all three. Note that the choice 3 = 1 + 2 (ao and ls) is the default within X-13ARIMA-SEATS, and is selected via the outlier tickbox in gretl's dialog window for seasonal adjustment via X13. 
</indent>

<indent>
• <@lit="critical">: a positive scalar, the critical value for defining outliers, the default being automatic, dependent on the sample size. Relevant only when <@lit="outliers"> is specified. 
</indent>

<indent>
• <@lit="logtrans">: should the input series be put in log form? 0 = no, 1 = yes, 2 = automatically selected (the default). Note that it is not recommended to pass the input series in log form; if you want the log to be used, pass the “raw” level but specify <@lit="logtrans=1">. 
</indent>

<indent>
• <@lit="trading_days">: should trading-day effects be included? 0 = no, 1 = yes, 2 = automatic (the default). 
</indent>

<indent>
• <@lit="working_days">: a simpler version of <@lit="trading_days"> with a single distinction between weekdays and weekends rather than individual day effects. 0 = no (the default), 1 = yes, 2 = automatic. Use only one of <@lit="trading_days"> and <@lit="working_days">. 
</indent>

<indent>
• <@lit="easter">: 1 to allow for an easter effect, as a supplement to either <@lit="trading_days"> or <@lit="working_days">, or 0 (the default). 
</indent>

<indent>
• <@lit="output">: a string to select the type of the output series, <@lit=""sa""> for deseasonalized (the default), <@lit=""trend""> for the estimated trend, or <@lit=""irreg""> for the irregular component. 
</indent>

<indent>
• <@lit="save_spc">: boolean flag, default 0; see below. 
</indent>

<@itl="Augmented results"> 

In some cases one may wish to obtain all three of the results available from X-13ARIMA via a single call to <@lit="deseas">. This is supported as follows. Pass the <@var="opts"> bundle in pointer form, and give the string <@lit=""all""> under the <@lit="output"> key. The direct return value is then the seasonally adjusted series, but on successful completion <@var="opts"> will contain a matrix named <@lit="results"> with three columns: seasonally adjusted, trend and irregular. Here's an illustration (where the direct return value is discarded). 

<code>          
     bundle b = _(output="all")
     deseas(y, &b)
     series y_dseas = b.results[,1]
     series y_trend = b.results[,2]
     series y_irreg = b.results[,3]
</code>

<@itl="Saving the X-13ARIMA specification"> 

The <@lit="save_spc"> flag can be used to save the content of the X-13ARIMA input file written by gretl. The options bundle should be passed in pointer form and the specification (as a string) can be found under the key <@lit="x13a_spc">. The following code illustrates saving this to file under the name <@lit="myspec.spc"> in the user's working directory. (Note that the <@lit=".spc"> extension is required by X-13ARIMA.) 

<code>          
     bundle b = _(save_spc=1)
     deseas(y, &b)
     outfile myspec.spc
        print b.x13a_spc
     end outfile
</code>

# det linalg
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the determinant of <@var="A">, computed via the LU factorization. If what you actually want is the log determinant you should call <@ref="ldet"> instead. See also <@ref="rcond">, <@ref="cnumber">. 

# diag matrix
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Returns the principal diagonal of <@var="X"> in a column vector. Note: if <@var="X"> is an <@itl="m">×<@itl="n"> matrix, the number of elements of the output vector is min(<@mth="m">, <@mth="n">). See also <@ref="tr">. 

# diagcat matrix
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="B">  (matrix)

Returns the direct sum of <@var="A"> and <@var="B">, that is a matrix holding <@var="A"> in its north-west corner and <@var="B"> in its south-east corner. If both <@var="A"> and <@var="B"> are square, the resulting matrix is block-diagonal. 

# diff transforms
Output: 	same type as input 
Argument: 	<@var="y">  (series, matrix or list)

Computes first differences. If <@var="y"> is a series, or a list of series, starting values are set to <@lit="NA">. If <@var="y"> is a matrix, differencing is done by columns and starting values are set to 0. 

When a list is returned, the individual variables are automatically named according to the template <@lit="d_"> <@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="cum">, <@ref="ldiff">, <@ref="sdiff">. 

# digamma math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the digamma (or Psi) function of <@var="x">, that is the derivative of the log of the Gamma function. 

See also <@ref="lngamma">, <@ref="trigamma">. 

# distance math
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="metric">  (string, optional)
		<@var="Y">  (matrix, optional)

Computes distances between points on a metric that can be <@lit="euclidean"> (the default), <@lit="manhattan">, <@lit="hamming">, <@lit="chebyshev">, <@lit="cosine"> or <@lit="mahalanobis">. The string identifying the metric can be given as an unambiguous truncation. The additional metrics correlation, standardized Euclidean are supported via simple transformations of the inputs; see below. 

Each row of the <@itl="m">×<@itl="n"> matrix <@var="X"> is treated as a point in an <@mth="n">-dimensional space; in an econometric context this is likely to represent a single observation comprising the values of <@mth="n"> variables. 

<@itl="Standard cases"> 

This section applies to all metrics except the Mahalanobis distance, for which the syntax is slightly different (see below). 

If <@var="Y"> is not given, the return value is a column vector of length <@mth="m">(<@mth="m"> – 1)/2 comprising the non-redundant subset of all pairwise distances between the <@mth="m"> points (rows of <@var="X">). Given such a vector named <@lit="d">, the full symmetric matrix of inter-point distances (with zeros on the principal diagonal) can be constructed via 

<code>          
     D = unvech(d, 0)
</code>

since <@lit="d"> is akin to the vech of <@lit="D">, with diagonal elements omitted. The optional second argument to <@ref="unvech"> says that the diagonal should be filled with zeros. 

If <@var="Y"> is given, it must be a <@itl="p">×<@itl="n"> matrix, each row of which is again treated as a point in <@mth="n">-space. In this case the return value is an <@itl="m">×<@itl="p"> matrix whose <@mth="i,j"> element holds the distance between row <@mth="i"> of <@var="X"> and row <@mth="j"> of <@var="Y">. 

To obtain the distances from a given reference point (for example, the centroid) to each of <@mth="n"> data-points, give <@var="Y"> as a single row. 

<@itl="Definitions of the supported metrics"> 

<indent>
• <@lit="euclidean">: the square root of the sum of squared deviations in each of the dimensions. 
</indent>

<indent>
• <@lit="manhattan">: the sum of the absolute deviations in each of the dimensions. 
</indent>

<indent>
• <@lit="hamming">: the proportion of the dimensions in which the deviation is non-zero (so bounded by 0 and 1). 
</indent>

<indent>
• <@lit="chebyshev">: the greatest absolute deviation in any dimension. 
</indent>

<indent>
• <@lit="cosine">: 1 minus the cosine of the angle between the “points”, considered as vectors. 
</indent>

<@itl="Mahalanobis distance"> 

Mahalanobis distances are defined as the Euclidean distances between the points in question (rows of <@var="X">) and a given centroid, scaled by the inverse of a covariance matrix. In the simplest case the centroid is constituted by the sample means of the variables (columns of <@var="X">) and the covariance matrix is their sample covariance. 

These can be obtained by supplying as second argument the string “mahalanobis” or any unambiguous abbreviation, as in 

<code>          
     dmahal = distance(X, "mahal")
</code>

In this case the third argument <@var="Y"> is not supported, and the return value is a column vector of length <@mth="m"> with the Mahalanobis distances from the centroid of <@var="X"> (that is, its sample mean). In practice, the output matrix in this case is the same you get by executing the <@xrf="mahal"> command on a list of series corresponding to the columns of <@var="X">. 

To obtain Mahalanobis distances using a different centroid, <@lit="mu">, and/or inverse covariance matrix, <@lit="ICV">, the following syntax can be used: 

<code>          
     dmahal = distance(X*cholesky(ICV), "euc", mu)
</code>

<@itl="Other metrics"> 

Standardized Euclidean distances and correlation distances can be obtained as follows: 

<code>          
     # standardized euclidean
     dseu = distance(stdize(X), "eu")
     # correlation (based on cosine)
     dcor = distance(stdize(X', -1)', "cos")
</code>

# dnorm probdist
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the density of the standard normal distribution at <@var="x">. To get the density for a non-standard normal distribution at <@mth="x">, pass the <@mth="z">-score of <@mth="x"> to the <@lit="dnorm"> function and multiply the result by the Jacobian of the <@mth="z"> transformation, namely 1 over σ, as illustrated below: 

<code>          
     mu = 100
     sigma = 5
     x = 109
     fx = (1/sigma) * dnorm((x-mu)/sigma)
</code>

See also <@ref="cnorm">, <@ref="qnorm">. 

# dropcoll transforms
Output: 	list 
Arguments:	<@var="X">  (list)
		<@var="epsilon">  (scalar, optional)

Returns a list with the same elements as <@var="X">, but for the collinear series. Therefore, if all the series in <@var="X"> are linearly independent, the output list is just a copy of <@var="X">. 

The algorithm uses the QR decomposition (Householder transformation), so it is subject to finite precision error. In order to gauge the sensitivity of the algorithm, a second optional parameter <@var="epsilon"> may be specified to make the collinearity test more or less strict, as desired. The default value for <@var="epsilon"> is 1.0e-8. Setting <@var="epsilon"> to a larger value increases the probability of a series to be dropped. 

Example: 

<code>          
     nulldata 20
     set seed 9876
     series foo = normal()
     series bar = normal()
     series foobar = foo + bar
     list X = foo bar foobar
     list Y = dropcoll(X)
     list print X
     list print Y
     # set epsilon to a ridiculously small value
     list Y = dropcoll(X, 1.0e-30)
     list print Y
</code>

produces 

<code>          
     ? list print X
     foo bar foobar
     ? list print Y
     foo bar
     ? list Y = dropcoll(X, 1.0e-30)
     Replaced list Y
     ? list print Y
     foo bar foobar
</code>

# dsort matrix
Output: 	same type as input 
Argument: 	<@var="x">  (series, vector or strings array)

Sorts <@var="x"> in descending order, skipping observations with missing values when <@var="x"> is a series. See also <@ref="sort">, <@ref="values">. 

# dummify transforms
Output: 	list 
Arguments:	<@var="x">  (series)
		<@var="omitval">  (scalar, optional)

The argument <@var="x"> should be a discrete series. This function creates a set of dummy variables coding for the distinct values in the series. By default the smallest value is taken as the omitted category and is not explicitly represented. 

The optional second argument represents the value of <@var="x"> which should be treated as the omitted category. The effect when a single argument is given is equivalent to <@lit="dummify(x, min(x))">. To produce a full set of dummies, with no omitted category, use <@lit="dummify(x, NA)">. 

The generated variables are automatically named according to the template <@lit="D"><@var="varname"><@lit="_"><@var="i"> where <@var="varname"> is the name of the original series and <@var="i"> is a 1-based index. The original portion of the name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

# easterday calendar
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Given the year in argument <@var="x">, returns the date of Easter in the Gregorian calendar as <@mth=" month + day/100">. Note that April the 10th, is, under this convention, 4.1; hence, 4.2 is April the 20th, not April the 2nd (which would be 4.02). 

<code>          
     scalar e = easterday(2014)
     scalar m = floor(e)
     scalar d = round(100*(e-m))
</code>

# ecdf stats
Output: 	matrix 
Argument: 	<@var="y">  (series or vector)

Calculates the empirical CDF of <@var="y">. This is returned in a matrix with two columns: the first holds the sorted unique values of <@var="y"> and the second holds the cumulative relative frequency, that is the count of observations whose value is less than or equal to the value in the first column, divided by the total number of observations. 

# eigen linalg
Output: 	matrix 
Arguments:	<@var="A">  (square matrix)
		<@var="&V">  (reference to matrix, or <@lit="null">)
		<@var="&W">  (reference to matrix, or <@lit="null">)

Computes the eigenvalues, and optionally the right and/or left eigenvectors, of the <@itl="n">×<@itl="n"> matrix <@var="A">, which may be real or complex. The eigenvalues are returned in a complex column vector. To obtain the norm of the eigenvalues, you can use the <@ref="abs"> function, which accepts complex arguments. 

If you wish to retrieve the right eigenvectors (as an <@itl="n">×<@itl="n"> complex matrix), supply the name of an existing matrix, preceded by <@lit="&"> to indicate the “address” of the matrix in question, as the second argument. Otherwise this argument can be omitted. 

To retrieve the left eigenvectors (again, as a complex matrix), supply a matrix-address as the third argument. Note that if you want the left eigenvectors but not the right ones, you should use the keyword <@lit="null"> as a placeholder for the second argument. 

See also <@ref="eigensym">, <@ref="eigsolve">, <@ref="svd">. 

# eigengen linalg
Output: 	matrix 
Arguments:	<@var="A">  (square matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

<@itl="This is a legacy function, predating gretl's native support for complex matrices. It should not be used in newly written hansl scripts. Use"> <@ref="eigen"> <@itl="instead."> 

Computes the eigenvalues, and optionally the right eigenvectors, of the <@itl="n">×<@itl="n"> matrix <@var="A">. If all the eigenvalues are real an <@itl="n">×1 matrix is returned; otherwise the result is an <@itl="n">×2 matrix, the first column holding the real components and the second column the imaginary components. The eigenvalues are not guaranteed to be sorted in any particular order. 

The second argument must be either the name of an existing matrix preceded by <@lit="&"> (to indicate the “address” of the matrix in question), in which case an auxiliary result is written to that matrix, or the keyword <@lit="null">, in which case the auxiliary result is not produced. 

If a non-null second argument is given, the specified matrix will be over-written with the auxiliary result. (It is not required that the existing matrix be of the right dimensions to receive the result.) The output is organized as follows: 

<indent>
• If the <@mth="i">-th eigenvalue is real, the <@mth="i">-th column of <@mth="U"> will contain the corresponding eigenvector; 
</indent>

<indent>
• If the <@mth="i">-th eigenvalue is complex, the <@mth="i">-th column of <@var="U"> will contain the real part of the corresponding eigenvector and the next column the imaginary part. The eigenvector for the conjugate eigenvalue is the conjugate of the eigenvector. 
</indent>

In other words, the eigenvectors are stored in the same order as the eigenvalues, but the real eigenvectors occupy one column, whereas complex eigenvectors take two (the real part comes first); the total number of columns is still <@mth="n">, because the conjugate eigenvector is skipped. 

See also <@ref="eigensym">, <@ref="eigsolve">, <@ref="qrdecomp">, <@ref="svd">. 

# eigensym linalg
Output: 	matrix 
Arguments:	<@var="A">  (symmetric matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Works mostly as <@ref="eigen"> except that the argument <@var="A"> must be symmetric (in which case less calculation is required), and the eigenvalues are returned in ascending order. If you want to get the eigenvalues in descending order (and have the eigenvectors reordered correspondingly) you can do the following: 

<code>          
     matrix U
     e = eigensym(A, &U)
     Tmp = msortby((-e' | U)',1)'
     e = -Tmp[1,]'
     U = Tmp[2:,]
     # now largest to smallest eigenvalues
     print e U
</code>

Note: if you're interested in the eigen-decomposition of a matrix of the form <@mth="X'X"> it's preferable to compute the argument via the prime operator <@lit="X'X"> rather than using the more general syntax <@lit="X'*X">. The former expression uses a specialized algorithm which offers greater computational efficiency as well as ensuring that the result is exactly symmetric. 

# eigsolve linalg
Output: 	matrix 
Arguments:	<@var="A">  (symmetric matrix)
		<@var="B">  (symmetric matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Solves the generalized eigenvalue problem |<@mth="A"> – λ<@mth="B">| = 0, where both <@mth="A"> and <@mth="B"> are symmetric and <@mth="B"> is positive definite. The eigenvalues are returned directly, arranged in ascending order. If the optional third argument is given it should be the name of an existing matrix preceded by <@lit="&">; in that case the generalized eigenvectors are written to the named matrix. 

# epochday calendar
Output: 	scalar or series 
Arguments:	<@var="year">  (scalar or series)
		<@var="month">  (scalar or series)
		<@var="day">  (scalar or series)

Returns the number of the day in the current epoch specified by year, month and day. The epoch day equals 1 for the first of January in the year AD 1 on the proleptic Gregorian calendar; it stood at 733786 on 2010-01-01. If any of the arguments are given as series the value returned is a series, otherwise it is a scalar. 

By default the <@var="year">, <@var="month"> and <@var="day"> values are assumed to be given relative to the Gregorian calendar, but if the year is a negative value the interpretation switches to the Julian calendar. 

An alternative call is also supported: if a single argument is given, it is taken to be a date (or series of dates) in ISO 8601 “basic” numeric format, <@lit="YYYYMMDD">. So the following two calls produce the same result, namely 700115. 

<code>          
     eval epochday(1917, 11, 7)
     eval epochday(19171107)
</code>

For the inverse function, see <@ref="isodate"> and also (for the Julian calendar) <@ref="juldate">. 

# errmsg programming
Output: 	string 
Argument: 	<@var="errno">  (integer)

Retrieves the gretl error message associated with <@var="errno">. See also <@ref="$error">. 

# errorif programming
Output: 	scalar 
Arguments:	<@var="condition">  (boolean)
		<@var="msg">  (string)

Applicable only in the context of a user-defined function, or within an <@xrf="mpi"> block. If <@var="condition"> evaluates as non-zero, it causes execution of the current function to terminate with an error condition flagged; the <@var="msg"> argument is then printed as part of the message shown to the caller of the function in question. 

The return value from this function (1) is purely nominal. 

# exists data-utils
Output: 	integer 
Argument: 	<@var="name">  (string)

Returns non-zero if <@var="name"> is the identifier for a currently defined object, be it a scalar, a series, a matrix, list, string, bundle or array; otherwise returns 0. See also <@ref="typeof">. 

# exp math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns <@mth="e"><@sup="x">. Note that in case of matrix input the function acts element by element. For the matrix exponential function, see <@ref="mexp">. 

# fcstats stats
Output: 	matrix 
Arguments:	<@var="y">  (series or vector)
		<@var="f">  (series, list or matrix)
		<@var="U2">  (boolean, optional)

Produces a matrix holding several statistics which serve to evaluate <@var="f"> as a forecast of the observed data <@var="y">. 

If <@var="f"> is a series or vector the output is a column vector; if <@var="f"> is a list with <@mth="k"> members or a <@itl="T">×<@itl="k"> matrix the output has <@mth="k"> columns, each of which holds statistics for the corresponding element (series or column) of the input as a forecast of <@var="y">. 

In all cases the “vertical” dimension of the input (for a series or list the length of the current sample range, for a matrix the number of rows) must match across the two arguments. 

The rows of the returned matrix are as follows: 

<code>          
     1  Mean Error (ME)
     2  Root Mean Squared Error (RMSE)
     3  Mean Absolute Error (MAE)
     4  Mean Percentage Error (MPE)
     5  Mean Absolute Percentage Error (MAPE)
     6  Theil's U (U1 or U2)
     7  Bias proportion, UM
     8  Regression proportion, UR
     9  Disturbance proportion, UD
</code>

The variant of Theil's U shown by default depends on the nature of the data: if they are known to be time series then U2 is shown, otherwise U1 is produced. But this choice can be forced via the optional trailing argument: give a non-zero value to force U2, or zero to force U1. 

For details on the calculation of these statistics, and the interpretation of the <@mth="U"> values, please see chapter 35 of the <@pdf="Gretl User's Guide#chap:forecast">. 

# fdjac numerical
Output: 	matrix 
Arguments:	<@var="b">  (column vector)
		<@var="fcall">  (function call)
		<@var="h">  (scalar, optional)

Calculates a numerical approximation to the Jacobian associated with the <@mth="n">-vector <@var="b"> and the transformation function specified by the argument <@var="fcall">. The function call should take <@var="b"> as its first argument (either straight or in pointer form), followed by any additional arguments that may be needed, and it should return an <@itl="m">×1 matrix. On successful completion <@lit="fdjac"> returns an <@itl="m">×<@itl="n"> matrix holding the Jacobian. 

The optional third argument can be used to set the step size <@mth="h"> used in the approximation mechanism (see below); if this argument is omitted the step size is determined automatically. 

Here is an example of usage: 

<code>          
     matrix J = fdjac(theta, myfunc(&theta, X))
</code>

The function can use three different methods: simple forward-difference, bilateral difference or 4-nodes Richardson extrapolation. Respectively: 

<@mth="J"><@sub="0"> = <@mth="(f(x+h) - f(x))/h"> 

<@mth="J"><@sub="1"> = <@mth="(f(x+h) - f(x-h))/2h"> 

<@mth="J"><@sub="2"> = <@mth="[8(f(x+h) - f(x-h)) - (f(x+2h) - f(x-2h))] /12h"> 

The three alternatives above provide, generally, a trade-off between accuracy and speed. You can choose among methods via the <@xrf="set"> command: specify a value of 0, 1 or 2 for the <@lit="fdjac_quality"> variable. The default is 0. 

For more details and examples chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. 

See also <@ref="BFGSmax">, <@ref="numhess">, <@xrf="set">. 

# feval programming
Output: 	see below 
Arguments:	<@var="funcname">  (string)
		... (see below)

Primarily useful for writers of functions. The first argument should be the name of a function; the remaining arguments will be passed to the specified function. This permits treating the function identified by <@var="funcname"> as itself a variable. The return value is whatever the named function returns given the specified arguments. 

The example below illustrates some possible uses. 

<code>          
     function scalar utility (scalar c, scalar sigma)
         return (c^(1-sigma)-1)/(1-sigma)
     end function

     strings S = defarray("log", "utility")

     # call a 1-argument built-in function
     x = feval(S[1], 2.5)
     # call a user-defined function
     x = feval(S[2], 5, 0.5)
     # a 2-argument built-in function
     func = "zeros"
     m = feval(func, 5-2, sqrt(4))
     print m
     # a 3-argument built-in
     x = feval("monthlen", 12, 1980, 5)
</code>

There's a weak analogy between <@lit="feval"> and <@ref="genseries">: both functions render variable a syntactic element that is usually fixed at the time a script is composed. 

# fevd timeseries
Output: 	matrix 
Arguments:	<@var="target">  (integer)
		<@var="shock">  (integer)
		<@var="sys">  (bundle, optional)

This function provides a more flexible alternative to the accessor <@ref="$fevd"> for obtaining a forecast error variance decomposition (FEVD) matrix following estimation of a VAR or VECM. Without the final optional argument, it is available only when the last model estimated was a VAR or VECM. Alternatively, information on such a system can be stored in a bundle via the <@ref="$system"> accessor and subsequently passed to <@lit="fevd">. 

The <@var="target"> and <@var="shock"> arguments take the form of 1-based indices of the endogenous variables in the system, with 0 taken to mean “all”. The following code fragment illustrates usage. In the first example the matrix <@lit="fe1"> holds the shares of the FEVD for <@lit="y1"> due to each of <@lit="y1">, <@lit="y2"> and <@lit="y3"> (the rows therefore summing to 1). In the second, <@lit="fe2"> holds the contribution of <@lit="y2"> to the forecast error variance of all three variables (so the rows do not sum to 1). In the third case the return value is a column vector showing the “own share” of the FEVD for <@lit="y1">. 

<code>          
     var 4 y1 y2 y3
     bundle vb = $system
     matrix fe1 = fevd(1, 0, vb)
     matrix fe2 = fevd(0, 2, vb)
     matrix fe3 = fevd(1, 1, vb)
</code>

The number of periods (rows) over which the decomposition is traced is determined automatically based on the frequency of the data, but this can be overridden via the <@lit="horizon"> argument to the <@xrf="set"> command, as in <@lit="set horizon 10">. 

See also <@ref="irf">. 

# fft linalg
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Discrete Fourier transform. The input matrix <@var="X"> may be real or complex. The output is a complex matrix of the same dimensions as <@var="X">. 

Should it be necessary to compute the Fourier transform on several vectors with the same number of elements, it is more efficient to group them into a matrix rather than invoking <@lit="fft"> for each vector separately. See also <@ref="ffti">. 

# ffti linalg
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Inverse discrete Fourier transform. It is assumed that <@var="X"> contains <@mth="n"> complex column vectors. A matrix with <@mth="n"> columns is returned. 

Should it be necessary to compute the inverse Fourier transform on several vectors with the same number of elements, it is more efficient to group them into a matrix rather than invoking <@lit="ffti"> for each vector separately. See also <@ref="fft">. 

# filter timeseries
Output: 	see below 
Arguments:	<@var="x">  (series or matrix)
		<@var="a">  (scalar or vector, optional)
		<@var="b">  (scalar or vector, optional)
		<@var="y0">  (scalar, optional)
		<@var="x0">  (scalar or vector, optional)

Computes an ARMA-like filtering of the argument <@var="x">. The transformation can be written as 

<@mth="y"><@sub="t"> = <@mth="a"><@sub="0"> <@mth="x"><@sub="t"> + <@mth="a"><@sub="1"> <@mth="x"><@sub="t-1"> + ... <@mth="a"><@sub="q"> <@mth="x"><@sub="t-q"> + <@mth="b"><@sub="1"> <@mth="y"><@sub="t-1"> + ... <@mth="b"><@sub="p"><@mth="y"><@sub="t-p"> 

If argument <@var="x"> is a series, the result will be itself a series. Otherwise, if <@var="x"> is a matrix with <@mth="T"> rows and <@mth="k"> columns, the result will be a matrix of the same size, in which the filtering is performed column by column. 

The two arguments <@var="a"> and <@var="b"> are optional. They may be scalars, vectors or the keyword <@lit="null">. 

If <@var="a"> is a scalar, this is used as <@mth="a"><@sub="0"> and implies <@mth="q=0">; if it is a vector of <@mth="q+1"> elements, they contain the coefficients from <@mth="a"><@sub="0"> to <@mth="a"><@sub="q">. If <@var="a"> is <@lit="null"> or omitted, this is equivalent to setting <@mth="a"><@sub="0"> <@mth="=1"> and <@mth="q=0">. 

If <@var="b"> is a scalar, this is used as <@mth="b"><@sub="1"> and implies <@mth="p=1">; if it is a vector of <@mth="p"> elements, they contain the coefficients from <@mth="b"><@sub="1"> to <@mth="b"><@sub="p">. If <@var="b"> is <@lit="null"> or omitted, this is equivalent to setting <@mth="B(L)=1">. 

The optional scalar argument <@var="y0"> is taken to represent all values of <@mth="y"> prior to the beginning of sample (used only when <@mth="p > 0">). If omitted, it is understood to be 0. Similarly, the optional argument <@var="x0"> may be used to specify one or more pre-sample values of <@mth="x">, information that is relevant only when <@mth="q > 0">. Otherwise pre-sample values of <@mth="x"> are assumed to be zero. 

See also <@ref="bkfilt">, <@ref="bwfilt">, <@ref="fracdiff">, <@ref="hpfilt">, <@ref="movavg">, <@ref="varsimul">. 

Example: 

<code>          
     nulldata 5
     y = filter(index, 0.5, -0.9, 1)
     print index y --byobs
     x = seq(1,5)' ~ (1 | zeros(4,1))
     w = filter(x, 0.5, -0.9, 1)
     print x w
</code>

produces 

<code>          
          index            y

          1            1     -0.40000
          2            2      1.36000
          3            3      0.27600
          4            4      1.75160
          5            5      0.92356

          x (5 x 2)

          1   1
          2   0
          3   0
          4   0
          5   0

          w (5 x 2)

          -0.40000     -0.40000
           1.3600       0.36000
           0.27600     -0.32400
           1.7516       0.29160
           0.92356     -0.26244
</code>

# firstobs data-utils
Output: 	integer 
Arguments:	<@var="y">  (series)
		<@var="insample">  (boolean, optional)

Returns the 1-based index of the first non-missing observation for the series <@var="y">. By default the whole data range is examined, so if subsampling is in effect the value returned may be smaller than the accessor <@ref="$t1">. But if a non-zero value is given for <@var="insample"> only the current sample range is considered. See also <@ref="lastobs">. 

# fixname strings
Output: 	string 
Arguments:	<@var="rawname">  (string)
		<@var="underscore">  (boolean, optional)

Primarily intended for use in connection with the <@xrf="join"> command. Returns the result of converting <@var="rawname"> to a valid gretl identifier, which must start with a letter, contain nothing but (ASCII) letters, digits and the underscore character, and must not exceed 31 characters. The rules used in conversion are: 

1. Skip any leading non-letters. 

2. Until the 31-character limit is reached or the input is exhausted: transcribe “legal” characters; skip “illegal” characters apart from spaces; and replace one or more consecutive spaces with an underscore, unless the previous character transcribed is an underscore in which case space is skipped. 

If you are confident that the input is not too long (and hence subject to truncation), you may wish to have sequences of one or more illegal characters replaced with an underscore rather than just being deleted; this may produce a more readable identifier. To get this effect, supply a nonzero value for the optional second argument. But this is not advisable in the context of the <@xrf="join"> command, since the automatically “fixed” name will not use underscores in this way. 

# flatten data-utils
Output: 	see below 
Arguments:	<@var="A">  (array of matrices or strings)
		<@var="alt">  (boolean, optional)

“Flattens” either an array of matrices into a single matrix or an array of strings into a single string. 

In the matrix case the matrices in <@var="A"> are by default concatented horizontally, but if a non-zero value is supplied for <@var="alt"> the concatenation is vertical. In either case an error is flagged if the matrices are not conformable for the operation. See <@ref="msplitby"> for the inverse operation. 

In the string case the result holds the strings in <@var="A">, arranged one per line by default. If a non-zero numerical value is given for <@var="alt"> the strings are separated by spaces rather than newlines, but an alternative usage of <@var="alt"> is supported: you may give a specific string to use as the separator. 

# floor math
Output: 	same type as input 
Argument: 	<@var="y">  (scalar, series or matrix)

Returns the greatest integer less than or equal to <@var="x">. Note: <@ref="int"> and <@lit="floor"> differ in their effect for negative arguments: <@lit="int(-3.5)"> gives –3, while <@lit="floor(-3.5)"> gives –4. 

# fracdiff timeseries
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="d">  (scalar)

Returns the fractional difference of order <@var="d"> for the series <@var="y">. 

Note that in theory fractional differentiation is an infinitely long filter. In practice, presample values of <@mth="y"><@sub="t"> are assumed to be zero. 

A negative value of <@var="d"> can be given, in which case fractional integration is performed. 

# fzero numerical
Output: 	scalar 
Arguments:	<@var="fcall">  (function call)
		<@var="init">  (scalar or vector, optional)
		<@var="toler">  (scalar, optional)

Attempts to find a single root of a continuous (typically nonlinear) function <@mth="f">—that is, a value of the scalar variable <@mth="x"> such that <@mth="f">(<@mth="x">) = 0. The <@var="fcall"> argument should provide a call to the function in question; <@var="fcall"> may include an arbitrary number of arguments but the first one must be the scalar playing the role of <@mth="x">. On successful completion the value of the root is returned. 

The method used is that of <@bib="Ridders (1979);ridders79">. This requires an initial bracket {<@mth="x"><@sub="0">, <@mth="x"><@sub="1">} such that both <@mth="x"> values lie in the domain of the function and the respective function values are of opposite sign. Best results are likely to be obtained if the user can supply, via the second argument, a 2-vector holding suitable end-points for the bracket. Failing that, one can supply a single scalar value and <@lit="fzero"> will try to find a counterpart. If the second argument is omitted, <@mth="x"><@sub="0"> is initialized to a small positive value and we search for a suitable <@mth="x"><@sub="1">. 

The optional <@var="toler"> argument can be used to adjust the maximum acceptable absolute difference of <@mth="f">(<@mth="x">) from zero, the default being 1.0e–14. 

By default this function operates silently, but the progress of the iterative method can be exposed by executing the command “<@lit="set max_verbose on">” before calling <@lit="fzero">. 

Some simple examples follow. 

<code>          
     # Approximate pi by finding a zero for sin() in the
     # bracket 2.8 to 3.2
     x = fzero(sin(x), {2.8, 3.2})
     printf "\nx = %.12f vs pi = %.12f\n\n", x, $pi

     # Approximate the 'Omega constant' starting from x = 0.5
     function scalar f(scalar x)
         return log(x) + x
     end function
     x = fzero(f(x), 0.5)
     printf "x = %.12f f(x) = %.15f\n", x, f(x)
</code>

# gammafun math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the gamma function of <@var="x">. 

See also <@ref="bincoeff"> and <@ref="lngamma">. 

# genseries programming
Output: 	scalar 
Arguments:	<@var="varname">  (string)
		<@var="rhs">  (series)

Provides the script writer with a convenient means of generating series whose names are not known in advance, and/or creating a series and appending it to a list in a single operation. 

The first argument gives the name of the series to create (or modify); this can be a string literal, a string variable, or an expression that evaluates to a string. The second argument, <@var="rhs"> (“right-hand side”), defines the source series: this can be the name of an existing series or an expression that evaluates to a series, as would appear to the right of the equals sign when defining a series in the usual way. 

The return value from this function is the ID number of the series in the dataset, a value suitable for inclusion in a list (or –1 on failure). 

For example, suppose you want to add <@mth="n"> random normal series to the dataset and put them all into a named list. The following will do the job: 

<code>          
     nulldata 10
     list Normals = null
     scalar n = 3
     loop i = 1 .. n
         Normals += genseries(sprintf("norm%d", i), normal())
     endloop
</code>

On completion <@lit="Normals"> will contain the series <@lit="norm1">, <@lit="norm2"> and <@lit="norm3"> . 

Those who find <@lit="genseries"> useful may also like to explore <@ref="feval">. 

# geoplot data-utils
Output: 	none 
Arguments:	<@var="mapfile">  (string)
		<@var="payload">  (series, optional)
		<@var="options">  (bundle, optional)

Calls for production of a map, when suitable geographical data are present. In most cases the <@var="mapfile"> argument should be given as <@ref="$mapfile">, an accessor that retrieves the name of the relevant GeoJSON file or ESRI shapefile. The optional <@var="payload"> argument is used to give the name of a series with which to colorize the regions of the map. And the final bundle argument enables you to set numerous options. 

See the geoplot documentation, <@adb="geoplot.pdf">, for full details and examples. This explains all the settings configurable via the <@var="options"> argument. 

# getenv programming
Output: 	string 
Argument: 	<@var="s">  (string)

If an environment variable by the name of <@var="s"> is defined, returns the string value of that variable, otherwise returns an empty string. See also <@ref="ngetenv">. 

# getinfo data-utils
Output: 	bundle 
Argument: 	<@var="y">  (series)

Returns information on the specified series, which may be given by name or ID number. The returned bundle contains all the attributes which can be set via the <@xrf="setinfo"> command. It also contains additional information relevant for series that have been created as transformations of primary data (lags, logs, etc.): this includes the gretl command word for the transformation under the key “transform” and the name of the associated primary series under “parent”. For lagged series, the specific lag number can be found under the key “lag”. 

Here is an example of usage: 

<code>          
     open data9-7
     lags QNC
     bundle b = getinfo(QNC_2)
     print b
</code>

On executing the above we see: 

<code>          
     has_string_table = 0
     lag = 2
     parent = QNC
     name = QNC_2
     graph_name =
     coded = 0
     discrete = 0
     transform = lags
     description = = QNC(t - 2)
</code>

To test whether series 5 in a dataset is a lagged term one can do this sort of thing: 

<code>          
     if getinfo(5).lag != 0
        printf "series 5 is a lag of %s\n", getinfo(5).parent
     endif
</code>

Note that the dot notation to access bundle members can be used even when the bundle is “anonymous” (not saved under its own name). 

# getkeys data-utils
Output: 	array of strings 
Argument: 	<@var="b">  (bundle)

Returns an array of strings holding the keys identifying the contents of <@var="b">. If the bundle is empty an empty array is returned. 

# getline strings
Output: 	scalar 
Arguments:	<@var="source">  (string)
		<@var="&target">  (reference to string)

This function is used to read successive lines from <@var="source">, which should be a named string variable. On each call a line from the source is written to <@var="target"> (which must also be a named string variable, given in pointer form), with the newline character stripped off. The valued returned is 1 if there was anything to be read (including blank lines), 0 if the source has been exhausted. 

Here is an example in which the content of a text file is broken into lines: 

<code>          
     string s = readfile("data.txt")
     string line
     scalar i = 1
     loop while getline(s, &line)
         printf "line %d = '%s'\n", i++, line
     endloop
</code>

In this example we can be sure that the source is exhausted when the loop terminates. If the source might not be exhausted you should follow your regular call(s) to <@lit="getline"> with a “clean up” call, in which <@var="target"> is replaced by <@lit="null"> (or omitted altogether) as in 

<code>          
     getline(s, &line) # get a single line
     getline(s, null) # clean up
</code>

Note that although the reading position advances at each call to <@lit="getline">, <@var="source"> is not modified by this function, only <@var="target">. 

# ghk stats
Output: 	matrix 
Arguments:	<@var="C">  (matrix)
		<@var="A">  (matrix)
		<@var="B">  (matrix)
		<@var="U">  (matrix)
		<@var="&dP">  (reference to matrix, or <@lit="null">)

Computes the GHK (Geweke, Hajivassiliou, Keane) approximation to the multivariate normal distribution function; see for example <@bib="Geweke (1991);geweke91">. The value returned is an <@itl="n">×1 vector of probabilities. 

The argument <@var="C"> (<@itl="m">×<@itl="m">) should give the Cholesky factor (lower triangular) of the covariance matrix of <@mth="m"> normal variates. The arguments <@var="A"> and <@var="B"> should both be <@itl="n">×<@itl="m">, giving respectively the lower and upper bounds applying to the variates at each of <@mth="n"> observations. Where variates are unbounded, this should be indicated using the built-in constant <@ref="$huge"> or its negative. 

The matrix <@var="U"> should be <@itl="m">×<@itl="r">, with <@mth="r"> the number of pseudo-random draws from the uniform distribution; suitable functions for creating <@var="U"> are <@ref="muniform"> and <@ref="halton">. 

We illustrate below with a relatively simple case where the multivariate probabilities can be calculated analytically. The series <@lit="P"> and <@lit="Q"> should be numerically very similar to one another, <@lit="P"> being the “true” probability and <@lit="Q"> its GHK approximation: 

<code>          
     nulldata 20
     series inf1 = -2*uniform()
     series sup1 = 2*uniform()
     series inf2 = -2*uniform()
     series sup2 = 2*uniform()

     scalar rho = 0.25
     matrix V = {1, rho; rho, 1}

     series P = cdf(D, rho, inf1, inf2) - cdf(D, rho, sup1, inf2) \
     - cdf(D, rho, inf1, sup2) + cdf(D, rho, sup1, sup2)

     C = cholesky(V)
     U = halton(2, 100)

     series Q = ghk(C, {inf1, inf2}, {sup1, sup2}, U)
</code>

The optional <@var="dP"> argument can be used to retrieve the <@itl="n">×<@itl="k"> matrix of analytical derivatives of the probabilities, where <@mth="k"> equals 2<@mth="m"> + <@mth="m">(<@mth="m"> + 1)/2. The first <@mth="m"> columns hold the derivatives with respect to the lower bounds, the next <@mth="m"> those with respect to the upper bounds, and the remainder the derivatives with respect to the unique elements of the <@mth="C"> matrix in “vech” order. 

# gini stats
Output: 	scalar 
Argument: 	<@var="y">  (series or vector)

Returns Gini's inequality index for the (non-negative) series or vector <@var="y">. A Gini value of zero indicates perfect equality. The maximum Gini value for a series with <@mth="n"> members is (<@mth="n"> – 1)/<@mth="n">, occurring when only one member has a positive value; a Gini of 1.0 is therefore the limit approached by a large series with maximal inequality. 

# ginv linalg
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="tol">  (scalar, optional)

Returns <@mth="A"><@sup="+">, the Moore–Penrose or generalized inverse of the <@itl="r">×<@itl="c"> matrix <@var="A">, computed via the singular value decomposition. 

The result of this operation depends on the number of singular values of <@var="A"> that are found to be numerically 0. The <@var="tol"> optional parameter can be used for tweaking this aspect. Singular values are considered to be 0 if they are less than <@mth="m × tol × s">, where <@mth="m"> is the greater of <@mth="r"> and <@mth="c"> and <@mth="s"> is the largest singular value. If the second argument is omitted <@var="tol"> is set to machine epsilon (see <@ref="$macheps">). In some cases, you may want to set <@var="tol"> to a larger value (eg 1.0e-9) in order to avoid overestimating the rank of <@var="A">, which may lead to numerically unstable results. 

This matrix has the properties <@mth="A"> <@mth="A"><@sup="+"> <@mth="A"> = <@mth="A"> and <@mth="A"><@sup="+"> <@mth="A"> <@mth="A"><@sup="+"> = <@mth="A"><@sup="+">. Moreover, the products <@mth="A"> <@mth="A"><@sup="+"> and <@mth="A"><@sup="+"> <@mth="A"> are symmetric by construction. 

See also <@ref="inv">, <@ref="svd">. 

# GSSmax numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="f">  (function call)
		<@var="toler">  (scalar, optional)

One-dimensional maximization via the Golden Section Search method. The matrix <@var="b"> should be a 3-vector. On input the first element is ignored while the second and third elements set the lower and upper bounds on the search. The <@var="fncall"> argument should specify a call to a function that returns the value of the maximand; element 1 of <@var="b">, which will hold the current value of the adjustable parameter when the function is called, should be given as its first argument; any other required arguments may then follow. The function in question should be unimodal (should have no local maxima other than the global maximum) over the stipulated range, or GSS is not sure to find the maximum. 

On successful completion <@lit="GSSmax"> returns the optimum value of the maximand, while <@var="b"> holds the optimal parameter value along with the limits of its bracket. 

The optional third argument may be used to set the tolerance for convergence, that is, the maximum acceptable width of the final bracket for the parameter. If this argument is not given a value of 0.0001 is used. 

If the object is in fact minimization, either the function call should return the negative of the criterion or alternatively <@lit="GSSmax"> may be called under the alias <@lit="GSSmin">. 

Here is a simple example of usage: 

<code>          
     function scalar trigfunc (scalar theta)
         return 4 * sin(theta) * (1 + cos(theta))
     end function

     matrix m = {0, 0, $pi/2}
     eval GSSmax(&m, trigfunc(m[1]))
     printf "\n%10.7f", m
</code>

# GSSmin numerical
Output: 	scalar 

An alias for <@ref="GSSmax">; if called under this name the function acts as a minimizer. 

# halton matrix
Output: 	matrix 
Arguments:	<@var="m">  (integer)
		<@var="r">  (integer)
		<@var="offset">  (integer, optional)

Returns an <@itl="m">×<@itl="r"> matrix containing <@mth="m"> Halton sequences of length <@mth="r">; <@mth="m"> is limited to a maximum of 40. The sequences are constructed using the first <@mth="m"> primes. By default the first 10 elements of each sequence are discarded, but this figure can be adjusted via the optional <@var="offset"> argument, which should be a non-negative integer. See <@bib="Halton and Smith (1964);halton64">. 

# hdprod linalg
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="Y">  (matrix, optional)

Horizontal direct product. The two arguments must have the same number of rows, <@mth="r">. The return value is a matrix with <@mth="r"> rows, in which the <@mth="i">-th row is the Kronecker product of the corresponding rows of <@var="X"> and <@var="Y">. If <@var="Y"> is omitted, the “shorthand” syntax applies (see below). 

If <@var="X"> is an <@mth="r x k"> matrix and <@var="Y"> is an <@mth="r x m"> matrix, the result will be a matrix with <@mth="r"> rows and <@mth="km"> columns. 

This operation is called “horizontal direct product” in conformity to its implementation in the GAUSS programming language. Its equivalent in standard matrix algebra would be called the row-wise Khatri-Rao product, or “face-splitting” product in the signal processing literature. 

Example: the code 

<code>          
     A = {1,2,3; 4,5,6}
     B = {0,1; -1,1}
     C = hdprod(A, B)
</code>

produces the following matrix: 

<code>          
          0    1    0    2    0    3
         -4    4   -5    5   -6    6
</code>

<@itl="Shorthand syntax"> 

If <@var="X"> and <@var="Y"> are the same matrix, then each row of the result is the vectorization of a symmetric matrix. In these cases, the second argument may be omitted; however, the returned matrix will only contain the non-redundant columns, and will therefore have <@mth="k(k+1)/2"> columns. For example, 

<code>          
     A = {1,2,3; 4,5,6}
     C = hdprod(A)
</code>

produces 

<code>          
     1    2    3    4    6    9 
     16   20   24   25   30   36
</code>

Note that the <@mth="i">-th row of <@mth="C"> is <@mth="vech(a"><@sub="i"> <@mth="a"><@sub="i"><@mth="')">, where <@mth="a"><@sub="i"> is the <@mth="i">-th row of <@mth="A">. 

When using the shorthand syntax with complex matrices, the implicit second argument will be the <@itl="conjugate"> of the first one, so as to make each row of the result the symmetric vectorization of a Hermitian matrix. 

# hfdiff midas
Output: 	list 
Arguments:	<@var="hfvars">  (list)
		<@var="multiplier">  (scalar)

Given a <@xrf="MIDAS_list">, produces a list of the same length holding high-frequency first differences. The second argument is optional and defaults to unity: it can be used to multiply the differences by some constant. 

# hfldiff midas
Output: 	list 
Arguments:	<@var="hfvars">  (list)
		<@var="multiplier">  (scalar)

Given a <@xrf="MIDAS_list">, produces a list of the same length holding high-frequency log-differences. The second argument is optional and defaults to unity: it can be used to multiply the differences by some constant, for example one might give a value of 100 to produce (approximate) percentage changes. 

# hflags midas
Output: 	list 
Arguments:	<@var="minlag">  (integer)
		<@var="maxlag">  (integer)
		<@var="hfvars">  (list)

Given a <@xrf="MIDAS_list">, <@var="hfvars">, produces a list holding high-frequency lags <@var="minlag"> to <@var="maxlag">. Use positive values for actual lags, negative for leads. For example, if <@var="minlag"> is –3 and <@var="maxlag"> is 5 then the returned list will hold 9 series: 3 leads, the contemporary value, and 5 lags. 

Note that high-frequency lag 0 corresponds to the first high frequency period within a low frequency period, for example the first month of a quarter or the first day of a month. 

# hflist midas
Output: 	list 
Arguments:	<@var="x">  (vector)
		<@var="m">  (integer)
		<@var="prefix">  (string)

Produces from the vector <@var="x"> a <@xrf="MIDAS_list"> of <@var="m"> series, where <@var="m"> is the ratio of the frequency of observation for the variable in <@var="x"> to the base frequency of the current dataset. The value of <@var="m"> must be at least 3 and the length of <@var="x"> must be <@var="m"> times the length of the current sample range. 

The names of the series in the returned list are constructed from the given <@var="prefix"> (which must be an ASCII string of 24 characters or less, and valid as a gretl identifier), plus one or more digits representing the sub-period of the observation. An error is flagged if any of these names duplicate names of existing objects. 

# hpfilt timeseries
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="lambda">  (scalar, optional)
		<@var="one-sided">  (boolean, optional)

Returns the cycle component from application of the Hodrick–Prescott filter to series <@var="y">. If the smoothing parameter, <@var="lambda">, is not supplied then a data-based default is used, namely 100 times the square of the periodicity (100 for annual data, 1600 for quarterly data, and so on). 

By default the filter is the usual two-sided version, but if the optional third argument is given with a non-zero value a one-sided variant (with no look-ahead) is computed in the manner of <@bib="Stock and Watson (1999);stock-watson1999">. 

The most common use of the HP filter is detrending, but if it's the trend you are interested in that is easily obtained by subtraction, as in 

<code>          
     series hptrend = y - hfilt(y)
</code>

See also <@ref="bkfilt">, <@ref="bwfilt">. 

# hyp2f1 math
Output: 	scalar or matrix 
Arguments:	<@var="a">  (scalar)
		<@var="b">  (scalar)
		<@var="c">  (scalar)
		<@var="x">  (scalar or matrix)

Returns the Gauss hypergeometric function for real argument <@var="x">. 

If <@var="x"> is a scalar, the return value will be scalar; otherwise, it will be a matrix the same size as <@var="x">. 

# I matrix
Output: 	matrix 
Arguments:	<@var="n">  (integer)
		<@var="m">  (integer, optional)

If <@var="m"> is omitted, returns an identity matrix of order <@var="n">. Otherwise returns an <@itl="n">×<@itl="m"> matrix with ones on the main diagonal and zeros elsewhere. 

# Im complex
Output: 	matrix 
Argument: 	<@var="C">  (complex matrix)

Returns a real matrix of the same dimensions as <@var="C">, holding the imaginary part of the input matrix. See also <@ref="Re">. 

# imaxc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the row indices of the maxima of the columns of <@var="X">. 

See also <@ref="imaxr">, <@ref="iminc">, <@ref="maxc">. 

# imaxr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the column indices of the maxima of the rows of <@var="X">. 

See also <@ref="imaxc">, <@ref="iminr">, <@ref="maxr">. 

# imhof probdist
Output: 	scalar 
Arguments:	<@var="M">  (matrix)
		<@var="x">  (scalar)

Computes Prob(<@mth="u'Au"> < <@mth="x">) for a quadratic form in standard normal variates, <@mth="u">, using the procedure developed by <@bib="Imhof (1961);imhof61">. 

If the first argument, <@var="M">, is a square matrix it is taken to specify <@mth="A">, otherwise if it's a column vector it is taken to be the precomputed eigenvalues of <@mth="A">, otherwise an error is flagged. 

See also <@ref="pvalue">. 

# iminc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the row indices of the minima of the columns of <@mth="X">. 

See also <@ref="iminr">, <@ref="imaxc">, <@ref="minc">. 

# iminr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the column indices of the minima of the rows of <@mth="X">. 

See also <@ref="iminc">, <@ref="imaxr">, <@ref="minr">. 

# inbundle data-utils
Output: 	integer 
Arguments:	<@var="b">  (bundle)
		<@var="key">  (string)

Checks whether bundle <@var="b"> contains a data-item with name <@var="key">. The value returned is an integer code for the type of the item: 0 for no match, 1 for scalar, 2 for series, 3 for matrix, 4 for string, 5 for bundle, 6 for array and 7 for list. The function <@ref="typestr"> may be used to get the string corresponding to this code. 

# infnorm linalg
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the infinity-norm of <@var="X">, that is, the maximum across the rows of <@var="X"> of the sum of absolute values of the row elements. 

See also <@ref="onenorm">. 

# inlist data-utils
Output: 	integer 
Arguments:	<@var="L">  (list)
		<@var="y">  (series)

Returns the (1-based) position of <@var="y"> in list <@var="L">, or 0 if <@var="y"> is not present in <@var="L">. 

The second argument may be given as the name of a series or alternatively as an integer ID number. If you know that a series of a certain name (say <@lit="foo">) exists, then you can call this function as, for example, 

<code>          
     pos = inlist(L, foo)
</code>

Here you are, in effect, asking “Give me the position of series <@lit="foo"> in list <@lit="L"> (or 0 if it is not included in L).” However, if you are unsure whether a series of the given name exists, you should place the name in quotes: 

<code>          
     pos = inlist(L, "foo")
</code>

In this case you are asking, “If there's a series named <@lit="foo"> in <@lit="L"> give me its position, otherwise return 0.” 

# instring strings
Output: 	integer 
Arguments:	<@var="s1">  (string)
		<@var="s2">  (string)
		<@var="ign_case">  (boolean, optional)

This is a boolean relative of <@ref="strstr">: it returns 1 if <@var="s1"> contains <@var="s2">, 0 otherwise. So the conditional expression 

<code>          
     if instring("cattle", "cat")
</code>

is logically equivalent to, but more efficient than, 

<code>          
     if strlen(strstr("cattle", "cat")) > 0
</code>

If the optional argument <@var="ign_case"> is nonzero, the search is case-insensitive. For example, 

<code>          
     instring("Cattle", "cat")
</code>

returns 0, but 

<code>          
     instring("Cattle", "cat", 1)
</code>

returns 1. 

# instrings strings
Output: 	matrix 
Arguments:	<@var="S">  (array of strings)
		<@var="test">  (string)

Checks the elements of the strings array <@var="S"> for equality with <@var="test">. Returns a column vector of length equal to the number of matches, holding the positions of the matches within the array—or an empty matrix in case of no matches. 

Example: 

<code>          
     strings S = defarray("A", "B", "C", "B")
     eval instrings(S, "B")
     2
     4
</code>

# int math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the integer part of <@var="x">, truncating the fractional part. Note: <@lit="int"> and <@ref="floor"> differ in their effect for negative arguments: <@lit="int(-3.5)"> gives –3, while <@lit="floor(-3.5)"> gives –4. See also <@ref="round">, <@ref="ceil">. 

# interpol timeseries
Output: 	series 
Argument: 	<@var="x">  (series)

Returns a series in which missing values in <@var="x"> are imputed via linear interpolation, for time series data or in the time dimension of a panel dataset. Extrapolation is not performed; missing values are replaced only if they are both preceded and followed by valid observations. 

# inv linalg
Output: 	matrix 
Argument: 	<@var="A">  (square matrix)

Returns the inverse of <@var="A">. If <@var="A"> is singular or not square, an error message is produced and nothing is returned. Note that gretl checks automatically the structure of <@var="A"> and uses the most efficient numerical procedure to perform the inversion. 

The matrix types gretl checks for are: identity; diagonal; symmetric and positive definite; symmetric but not positive definite; and triangular. 

Note: it makes sense to use this function only if you plan to use the inverse of <@var="A"> more than once. If you just need to compute an expression of the form <@mth="A"><@sup="-1"><@mth="B">, you'll be much better off using the “division” operators <@lit="\"> and <@lit="/">. See chapter 17 of the <@pdf="Gretl User's Guide#chap:matrices"> for details. 

See also <@ref="ginv">, <@ref="invpd">. 

# invcdf probdist
Output: 	same type as input 
Arguments:	<@var="d">  (string)
		<@var="…">  (see below)
		<@var="u">  (scalar, series or matrix)

Inverse cumulative distribution function calculator. For a continuous distribution, returns <@mth="x"> such that <@mth="P(X ≤ x) = u">, for <@var="u"> in the interval 0 to 1. For a discrete distribution (Binomial or Poisson), returns the smallest <@mth="x"> such that <@mth="P(X ≤ x) ≥ u">. 

The distribution of <@mth="X"> is determined by the string <@var="d">. Between the arguments <@var="d"> and <@var="u">, zero or more additional scalar arguments are required to specify the parameters of the distribution, as follows. 

<indent>
• Standard normal (c = z, n, or N): no extra arguments 
</indent>

<indent>
• Gamma (g or G): shape; scale 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.); df (den.) 
</indent>

<indent>
• Binomial (b or B): probability; trials 
</indent>

<indent>
• Poisson (p or P): mean 
</indent>

<indent>
• Laplace (l or L): mean; scale 
</indent>

<indent>
• Standardized GED (E): shape 
</indent>

<indent>
• Non-central chi square (ncX): df, non-centrality parameter 
</indent>

<indent>
• Non-central F (ncF): df (num.), df (den.), non-centrality parameter 
</indent>

<indent>
• Non-central t (nct): df, non-centrality parameter 
</indent>

See also <@ref="cdf">, <@ref="critical">, <@ref="pvalue">. 

# invmills probdist
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the inverse Mills ratio at <@var="x">, that is the ratio between the standard normal density and the complement to the standard normal distribution function, both evaluated at <@var="x">. 

This function uses a dedicated algorithm which yields greater accuracy compared to calculation using <@ref="dnorm"> and <@ref="cnorm">, but the difference between the two methods is appreciable only for very large negative values of <@var="x">. 

See also <@ref="cdf">, <@ref="cnorm">, <@ref="dnorm">. 

# invpd linalg
Output: 	square matrix 
Argument: 	<@var="A">  (positive definite matrix)

Returns the inverse of the symmetric, positive definite matrix <@var="A">. This function is slightly faster than <@ref="inv"> for large matrices, since no check for symmetry is performed; for that reason it should be used with care. 

Note: if you're interested in the inversion of a matrix of the form <@mth="X'X">, where <@mth="X"> is a large matrix, it is preferable to compute it via the prime operator <@lit="X'X"> rather than using the more general syntax <@lit="X'*X">. The former expression uses a specialized algorithm which has the double advantage of being more efficient computationally and of ensuring that the result will be free by construction of machine precision artifacts that may render it numerically non-symmetric. 

# irf timeseries
Output: 	matrix 
Arguments:	<@var="target">  (integer)
		<@var="shock">  (integer)
		<@var="alpha">  (scalar between 0 and 1, optional)
		<@var="sys">  (bundle, optional)

Provides estimated impulse response functions pertaining to a VAR or VECM, traced out over a certain forecast horizon. Without the final optional argument, this function works only when the last model estimated was a VAR or VECM. Alternatively, information on such a system can be saved as a bundle via the <@ref="$system"> accessor and subsequently passed to <@lit="irf">. 

The <@var="target"> and <@var="shock"> arguments take the form of 1-based indices of the endogenous variables in the system, with 0 taken to mean “all”. The responses (expressed in the units of the <@var="target"> variable) are to an innovation of one standard deviation in the <@var="shock"> variable. If <@var="alpha"> is given a suitable positive value the estimates include a 1 – α confidence interval (so, for example, give 0.1 for a 90 percent interval). 

The following code fragment illustrates usage. In the first example the matrix <@lit="ir1"> holds the responses of <@lit="y1"> to innovations in each of <@lit="y1">, <@lit="y2"> and <@lit="y3"> (point estimates only since <@var="alpha"> is omitted). In the second, <@lit="ir2"> holds the responses of all targets to an innovation in <@lit="y2">, with 90 percent confidence intervals. In this case the returned matrix will have 9 columns: each response path occupies 3 adjacent columns giving point estimate, lower bound and upper bound. The last example produces a matrix with 27 columns: 3 per response for each target times each shock. 

<code>          
     var 4 y1 y2 y3
     matrix ir1 = irf(1, 0)
     matrix ir2 = irf(0, 2, 0.1)
     matrix ir3 = irf(0, 0, 0.1)
</code>

The number of periods (rows) over which the response is traced is determined automatically based on the frequency of the data, but this can be overridden via the <@xrf="set"> command, as in <@lit="set horizon 10">. 

When confidence intervals are produced they are derived via bootstrapping, with resampling of the original residuals. It is assumed that the lag order of the VAR or VECM is sufficient to eliminate serial correlation of the residuals. By default the number of bootstrap replications is 1999, but that can be adjusted via <@xrf="set">, as in 

<code>          
     set boot_iters 2999
</code>

See also <@ref="fevd">, <@ref="vma">. 

# irr math
Output: 	scalar 
Argument: 	<@var="x">  (series or vector)

Returns the Internal Rate of Return for <@var="x">, considered as a sequence of payments (negative) and receipts (positive). See also <@ref="npv">. 

# iscomplex data-utils
Output: 	scalar 
Argument: 	<@var="name">  (string)

Tests whether <@var="name"> is the identifier for a complex matrix. The return value is one of the following: 

<@lit="NA">: <@var="name"> does not identify a matrix. 

<@lit="0">: <@var="name"> identifies a real matrix, composed entirely of regular floating-point numbers (“doubles”, in C parlance). 

<@lit="1">: <@var="name"> identifies a “nominally” complex matrix, composed of numbers with both a real and an imaginary part, but in which all imaginary parts are zero. 

<@lit="2">: the matrix in question holds at least one “genuinely” complex value, with a non-zero imaginary part. 

# isconst data-utils
Output: 	integer 
Arguments:	<@var="y">  (series or vector)
		<@var="panel-code">  (integer, optional)

Without the optional second argument, returns 1 if <@var="y"> has a constant value over the current sample range (or over its entire length if <@var="y"> is a vector), otherwise 0. 

The second argument is accepted only if the current dataset is a panel and <@var="y"> is a series. In that case a <@var="panel-code"> value of 0 calls for a check for time-invariance, while a value of 1 means check for cross-sectional invariance (that is, in each time period the value of <@var="y"> is the same for all groups). 

If <@var="y"> is a series, missing values are ignored in checking for constancy. 

# isdiscrete data-utils
Output: 	integer 
Argument: 	<@var="name">  (string)

If <@var="name"> is the identifier for a currently defined series, returns 1 if the series is marked as discrete-valued, otherwise 0. If <@var="name"> does not identify a series, returns <@lit="NA">. 

# isdummy data-utils
Output: 	integer 
Argument: 	<@var="x">  (series or vector)

If all the values contained in <@var="x"> are 0 or 1 (or missing), returns the number of ones, otherwise 0. 

# isnan data-utils
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or matrix)

Given a scalar argument, returns 1 if <@var="x"> is “Not a Number” (NaN), otherwise 0. Given a matrix argument, returns a matrix of the same dimensions with 1s in positions where the corresponding element of the input is NaN and 0s elsewhere. 

# isoconv calendar
Output: 	integer 
Arguments:	<@var="date">  (series)
		<@var="&year">  (reference to series)
		<@var="&month">  (reference to series)
		<@var="&day">  (reference to series, optional)

Given a series <@var="date"> holding dates in ISO 8601 “basic” format (<@lit="YYYYMMDD">), this function writes the year, month and (optionally) day components into the series named by the second and subsequent arguments. An example call, assuming the series <@lit="dates"> contains suitable 8-digit values: 

<code>          
     series y, m, d
     isoconv(dates, &y, &m, &d)
</code>

The nominal return value is 0 on successful completion; in case of failure an error is flagged. 

# isocountry strings
Output: 	same type as input 
Arguments:	<@var="source">  (string or array of strings)
		<@var="output">  (integer, optional)

This function maps between the four designations for countries present in ISO 3166, namely 

<indent>
1. Country name 
</indent>

<indent>
2. Alpha-2 code (two uppercase letters) 
</indent>

<indent>
3. Alpha-3 code (three uppercase letters) 
</indent>

<indent>
4. Numeric code (3 digits) 
</indent>

Given a country's designation in one form, the return value is its designation in the form (1 to 4) selected by the optional <@var="output"> argument or, if this argument is omitted, a default conversion as follows: when <@var="source"> is a country name the return value is the country's 2-letter code; otherwise the return value is the country name. Various valid calls are illustrated below in interactive form. 

<code>          
     ? eval isocountry("Bolivia")
     BO
     ? eval isocountry("Bolivia", 3)
     BOL
     ? eval isocountry("GB")
     United Kingdom of Great Britain and Northern Ireland
     ? eval isocountry("GB", 3)
     GBR
     ? strings S = defarray("ES", "DE", "SD")
     ? strings C = isocountry(S)
     ? print C
     Array of strings, length 3
     [1] "Spain"
     [2] "Germany"
     [3] "Sudan"
     ? matrix m = {4, 840}
     ? C = isocountry(m)
     ? print C
     Array of strings, length 2
     [1] "Afghanistan"
     [2] "United States of America"
</code>

When <@var="source"> is in form 4 (numeric code) this can be given as a string or array of strings (for example, “032” for Argentina) or in numeric form. In the latter case <@var="source"> may be given as a series or vector, though an error will be flagged if any of the numbers are out of the range 0 to 999. 

In all cases (even when output form 4 is selected) a string, or array of strings, is returned; if numeric values are required these may be obtained using <@ref="atof">. If <@var="source"> is not matched by any entry in the ISO 3166 table the return value is an empty string, in which case a warning is printed. 

# isodate calendar
Output: 	see below 
Arguments:	<@var="ed">  (scalar or series)
		<@var="as-string">  (boolean, optional)

The argument <@var="ed"> is interpreted as an epoch day, which equals 1 for the first of January in the year AD 1 on the proleptic Gregorian calendar. The default return value (of the same type as <@var="ed">) is an 8-digit number, or a series of such numbers, on the pattern <@lit="YYYYMMDD"> (ISO 8601 “basic” format), giving the Gregorian calendar date corresponding to the epoch day. 

If <@var="ed"> is a scalar (only) and the optional second argument <@var="as-string"> is non-zero, the return value is not numeric but rather a string on the pattern <@lit="YYYY-MM-DD"> (ISO 8601 “extended” format). 

For the inverse function, see <@ref="epochday">; also see <@ref="juldate">. 

# isoweek calendar
Output: 	see below 
Arguments:	<@var="year">  (scalar or series)
		<@var="month">  (scalar or series)
		<@var="day">  (scalar or series)

Returns the ISO 8601 week number corresponding to the date(s) specified by the three arguments, or <@lit="NA"> if the date is invalid. Note that all three arguments must be of the same type, either scalars (integers) or series. 

ISO weeks are numbered from 01 to 53; most years have 52 weeks but on average 71 out of 400 years have 53 weeks. The ISO 8601 definition for week 01 is the week containing the year's first Thursday on the Gregorian calendar. For a full account see <@url="https://en.wikipedia.org/wiki/ISO_week_date">. 

An alternative call is also supported: if a single argument is given, it is taken to be a date (or series of dates) in ISO 8601 “basic” numeric format, <@lit="YYYYMMDD">. So the following two calls produce the same result, namely 13. 

<code>          
     eval isoweek(2022, 4, 1)
     eval isoweek(20220401)
</code>

# iwishart probdist
Output: 	matrix 
Arguments:	<@var="S">  (symmetric matrix)
		<@var="v">  (integer)

Given <@var="S"> (a positive definite <@itl="p">×<@itl="p"> scale matrix), returns a drawing from the Inverse Wishart distribution with <@var="v"> degrees of freedom. The returned matrix is also <@itl="p">×<@itl="p">. The algorithm of <@bib="Odell and Feiveson (1966);odell-feiveson66"> is used. 

# jsonget data-utils
Output: 	string 
Arguments:	<@var="buf">  (string)
		<@var="path">  (string)
		<@var="nread">  (reference to scalar, optional)

The argument <@var="buf"> should be a JSON buffer, as may be retrieved from a suitable website via the <@ref="curl"> function, and the <@var="path"> argument should be a JsonPath specification. 

This function returns a string representing the data found in the buffer at the specified path. Data types of double (floating-point), int (integer) and string are supported. In the case of doubles or ints, their string representation is returned (using the “C” locale for doubles). If the object to which <@var="path"> refers is an array, the members are printed one per line in the returned string. 

By default an error is flagged if <@var="path"> is not matched in the JSON buffer, but this behavior is modified if you pass the third, optional argument: in that case the argument retrieves a count of the matches and an empty string is returned if there are none. Example call: 

<code>          
     ngot = 0
     ret = jsonget(jbuf, "$.some.thing", &ngot)
</code>

However, an error is still flagged in case of a malformed query. 

An accurate account of JsonPath syntax can be found at <@url="http://goessner.net/articles/JsonPath/">. However, please note that the back-end for <@lit="jsonget"> is provided by <@lit="json-glib">, which does not necessarily support all elements of JsonPath. Moreover, the exact functionality of <@lit="json-glib"> may differ depending on the version you have on your system. See <@url="https://wiki.gnome.org/Projects/JsonGlib"> if you need details. 

That said, the following operators should be available to <@lit="jsonget">: 

<indent>
• root node, via the <@lit="$"> character 
</indent>

<indent>
• recursive descent operator: <@lit=".."> 
</indent>

<indent>
• wildcard operator: <@lit="*"> 
</indent>

<indent>
• subscript operator: <@lit="[]"> 
</indent>

<indent>
• set notation operator, for example <@lit="[i,j]"> 
</indent>

<indent>
• slice operator: <@lit="[start:end:step]"> 
</indent>

# jsongetb data-utils
Output: 	bundle 
Arguments:	<@var="buf">  (string)
		<@var="path">  (string, optional)

The argument <@var="buf"> should be a JSON buffer, as may be retrieved from a suitable website via the <@ref="curl"> function. The specification and effect of the optional <@var="path"> argument are described below. 

The return value is a bundle whose structure basically mirrors that of the input: JSON objects become gretl bundles and JSON arrays become gretl arrays, each of which can hold strings, bundles or arrays. JSON “value” nodes become either members of bundles or elements of arrays; in the latter case numerical values are converted to strings using <@lit="sprintf">. Note that although the JSON specification allows arrays of mixed type these cannot be handled by <@lit="jsongetb"> since gretl arrays must be of a single type. 

The <@var="path"> argument can be used to limit the JSON elements included in the returned bundle. This is not a “JsonPath” as described in the help for <@ref="jsonget">; it is a simple construct subject to the following specification. 

<indent>
• <@var="path"> is a slash-separated array of elements where slash (“/”) indicates moving to one level “deeper” in the JSON tree represented by <@var="buf">. A leading slash is allowed but not required; implicitly the path always starts at the root. No extraneous white-space characters should be included. 
</indent>

<indent>
• Each slash-separated element must take one of the following forms: (a) a single name, in which case only a JSON element whose name matches at the given structural level will be included; or (b) “*” (asterisk), in which case all elements at the given level are included; or (c) an array of comma-separated names, enclosed in braces (“{” and “}”), in which case only JSON elements whose names match one of the given names will be included. 
</indent>

See also the string-oriented <@ref="jsonget">; depending on your purpose one of these functions may be more helpful than the other. 

# juldate calendar
Output: 	see below 
Arguments:	<@var="ed">  (scalar or series)
		<@var="as-string">  (boolean, optional)

The argument <@var="ed"> is interpreted as an epoch day, which equals 1 for the first of January in the year AD 1 on the proleptic Gregorian calendar. The default return value—of the same type as <@var="ed">—is an 8-digit number, or a series of such numbers, on the pattern <@lit="YYYYMMDD"> (ISO 8601 “basic” format), giving the Julian calendar date corresponding to the epoch day. 

If <@var="ed"> is a scalar (only) and the optional second argument <@var="as-string"> is non-zero, the return value is not numeric but rather a string on the pattern <@lit="YYYY-MM-DD"> (ISO 8601 “extended” format). 

See also <@ref="isodate">. 

# kdensity nonparam
Output: 	matrix 
Arguments:	<@var="x">  (series, list or matrix)
		<@var="scale">  (scalar, optional)
		<@var="control">  (boolean, optional)

Computes a kernel density estimate (or set of estimates) for the argument <@var="x">, which may be a single series or vector or a list or matrix with more than column. The returned matrix has <@mth="k"> + 1 columns, where <@mth="k"> is the number of elements (series or columns) in <@var="x">. The first column holds a set of evenly spaced abscissae and the rest hold the estimated density or densities at each of these points. 

The optional <@var="scale"> parameter can be used to adjust the degree of smoothing relative to the default of 1.0 (higher values produce a smoother result). The <@var="control"> parameter acts as a boolean: 0 (the default) means that the Gaussian kernel is used; a non-zero value switches to the Epanechnikov kernel. 

A plot of the results may be obtained using the <@xrf="gnuplot"> command, as illustrated below. Note that the column containing the abscissae should come last for plotting. 

<code>          
     matrix d = kdensity(x)
     # if x has a single element
     gnuplot 2 1 --matrix=d --with-lines --fit=none
     # if x has two elements
     gnuplot 2 3 1 --matrix=d --with-lines --fit=none
</code>

# kdsmooth sspace
Output: 	integer 
Arguments:	<@var="&Mod">  (reference to bundle)
		<@var="MSE">  (boolean, optional)

Performs disturbance smoothing for a Kalman bundle previously set up by means of <@ref="ksetup"> and returns 0 on successful completion or non-zero if numerical problems are encountered. The return value should be checked before making using of results. 

On successful completion, the smoothed disturbances will be available as <@lit="Mod.smdist">. 

The optional <@var="MSE"> argument determines the contents of the <@lit="Mod.smdisterr"> key. If 0 or omitted, this matrix will contain the unconditional standard errors of the smoothed disturbances, which are normally used to compute the so-called <@itl="auxiliary residuals">. Otherwise, <@lit="Mod.smdisterr"> will contain the estimated root mean square deviations of the auxiliary residuals from their true value. 

For more details see chapter 36 of the <@pdf="Gretl User's Guide#chap:kalman">. 

See also <@ref="ksetup">, <@ref="kfilter">, <@ref="ksmooth">, <@ref="ksimul">. 

# kfilter sspace
Output: 	scalar 
Argument: 	<@var="&Mod">  (reference to bundle)

Performs a forward, filtering pass on a Kalman bundle previously set up by means of <@ref="ksetup"> and returns 0 on successful completion or 1 if numerical problems are encountered. 

On successful completion, the one-step-ahead prediction errors will be available as <@lit="Mod.prederr"> and the sequence of their covariance matrices as <@lit="Mod.pevar">. Moreover, the key <@lit="Mod.llt"> gives access to a <@mth="T">-vector containing the log-likelihood by observation. 

For more details see chapter 36 of the <@pdf="Gretl User's Guide#chap:kalman">. 

See also <@ref="kdsmooth">, <@ref="ksetup">, <@ref="ksmooth">, <@ref="ksimul">. 

# kmeier nonparam
Output: 	matrix 
Arguments:	<@var="d">  (series or vector)
		<@var="cens">  (series or vector, optional)

Given a sample of duration data, <@var="d">, possibly accompanied by a record of censoring status, <@var="cens">, computes the Kaplan–Meier nonparametric estimator of the survival function (<@bib="Kaplan and Meier, 1958;kaplan-meier">). The returned matrix has three columns holding, respectively, the sorted unique values in <@var="d">, the estimated survival function corresponding to the duration value in column 1 and the (large sample) standard error of the estimator, calculated via the method of <@bib="Greenwood (1926);greenwood26">. 

If the <@var="cens"> series is given, the value 0 is taken to indicate an uncensored observation while a value of 1 indicates a right-censored observation (that is, the period of observation of the individual in question has ended before the duration or spell has been recorded as terminated). If <@var="cens"> is not given, it is assumed that all observations are uncensored. (Note: the semantics of <@var="cens"> may be extended at some point to cover other types of censoring.) 

See also <@ref="naalen">. 

# kpsscrit stats
Output: 	matrix 
Arguments:	<@var="T">  (scalar)
		<@var="trend">  (boolean)

Returns a row vector containing critical values at the 10, 5 and 1 percent levels for the KPSS test for stationarity of a time series. <@var="T"> should give the number of observations and <@var="trend"> should be 1 if the test includes a trend, 0 otherwise. 

The critical values given are based on response surfaces estimated in the manner set out by <@bib="Sephton (Economics Letters, 1995);sephton95">. See also the <@xrf="kpss"> command. 

# ksetup sspace
Output: 	bundle 
Arguments:	<@var="Y">  (series, matrix or list)
		<@var="Z">  (scalar or matrix)
		<@var="T">  (scalar or matrix)
		<@var="Q">  (scalar or matrix)
		<@var="R">  (matrix, optional)

Sets up a Kalman bundle, that is an object which contains all the information needed to define a linear state space model of the form 

  <@fig="kalman1">

where Var<@mth="(u) = R">, and state transition equation 

  <@fig="kalman2">

where Var<@mth="(v) = Q">. 

Objects created via this function can be later used via the dedicated functions <@ref="kfilter"> for filtering, <@ref="ksmooth"> and <@ref="kdsmooth"> for smoothing and <@ref="ksimul"> for performing simulations. 

The class of models that gretl can handle is in fact much wider than the one implied by the representation above: it is possible to have time-varying models, models with diffuse priors and exogenous variable in the measurement equation and models with cross-correlated innovations. For further details, see chapter 36 of the <@pdf="Gretl User's Guide#chap:kalman">. 

See also <@ref="kdsmooth">, <@ref="kfilter">, <@ref="ksmooth">, <@ref="ksimul">. 

# ksimul sspace
Output: 	scalar 
Argument: 	<@var="&Mod">  (reference to bundle)

Uses a Kalman bundle previously set up by means of <@ref="ksetup"> to simulate data. 

For details see chapter 36 of the <@pdf="Gretl User's Guide#chap:kalman">. 

See also <@ref="ksetup">, <@ref="kfilter">, <@ref="ksmooth">. 

# ksmooth sspace
Output: 	integer 
Argument: 	<@var="&Mod">  (reference to bundle)

Performs a fixed-point smoothing (backward) pass on a Kalman bundle previously set up by means of <@ref="ksetup"> and returns 0 on successful completion or non-zero if numerical problems are encountered. The return value should be checked before making using of results. 

On successful completion, the smoothed states will be available as <@lit="Mod.state"> and the sequence of their covariance matrices as <@lit="Mod.stvar">. For more details see chapter 36 of the <@pdf="Gretl User's Guide#chap:kalman">. 

See also <@ref="ksetup">, <@ref="kdsmooth">, <@ref="kfilter">, <@ref="ksimul">. 

# kurtosis stats
Output: 	scalar 
Argument: 	<@var="x">  (series)

Returns the excess kurtosis of the series <@var="x">, skipping any missing observations. 

# lags transforms
Output: 	list or matrix 
Arguments:	<@var="p">  (scalar or vector)
		<@var="y">  (series, list or matrix)
		<@var="bylag">  (boolean, optional)

If the first argument is a scalar, generates lags 1 to <@var="p"> of the series <@var="y">, or if <@var="y"> is a list, of all series in the list, or if <@var="y"> is a matrix, of all columns in the matrix. If <@var="p"> = 0 and <@var="y"> is a series or list, the maximum lag defaults to the periodicity of the data; otherwise <@var="p"> must be positive. 

If a vector is given as the first argument, the lags generated are those specified in the vector. Common usage in this case would be to give <@var="p"> as, for example, <@lit="seq(3,7)">, hence omitting the first and second lags. However, it is OK to give a vector with gaps, as in <@lit="{3,5,7}">, although the lags should always be given in ascending order. 

In the case of list output, the generated variables are automatically named according to the template <@var="varname"> <@lit="_"> <@var="i"> where <@var="varname"> is the name of the original series and <@var="i"> is the specific lag. The original portion of the name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

When <@var="y"> is a list, or a matrix with more than one column, and the lag order is greater than 1, the default ordering of the terms in the return value is by variable: all lags of the first input series or column followed by all lags of the second, and so on. The optional third argument can be used to change this: if <@var="bylag"> is non-zero then the terms are ordered by lag: lag 1 of all the input series or columns, then lag 2 of all the series or columns, and so on. 

See also <@ref="mlag"> for use with matrices. 

# lastobs data-utils
Output: 	integer 
Arguments:	<@var="y">  (series)
		<@var="insample">  (boolean, optional)

Returns the 1-based index of the last non-missing observation for the series <@var="y">. By default the whole data range is examined, so if subsampling is in effect the value returned may be larger than the accessor <@ref="$t2">. But if a non-zero value is given for <@var="insample"> only the current sample range is considered. See also <@ref="firstobs">. 

# ldet linalg
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the natural log of the determinant of <@mth="A">, computed via the LU factorization. Note that this is more efficient than calling <@ref="det"> and taking the log of the result. Moreover, in some cases <@lit="ldet"> is able to return a valid result even if the determinant of <@mth="A"> is numerically “infinite” (exceeds the C library's maximum double-precision number). See also <@ref="rcond">, <@ref="cnumber">. 

# ldiff transforms
Output: 	same type as input 
Argument: 	<@var="y">  (series or list)

Computes log differences; starting values are set to <@lit="NA">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="ld_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="diff">, <@ref="sdiff">. 

# lincomb transforms
Output: 	series 
Arguments:	<@var="L">  (list)
		<@var="b">  (vector)

Computes a new series as a linear combination of the series in the list <@var="L">. The coefficients are given by the vector <@var="b">, which must have length equal to the number of series in <@var="L">. 

See also <@ref="wmean">. 

# linearize transforms
Output: 	series 
Argument: 	<@var="x">  (series)

Depends on having TRAMO installed. Returns a “linearized” version of the input series; that is, a series in which any missing values are replaced by interpolated values and outliers are adjusted. TRAMO's fully automatic mechanism is used; consult the TRAMO documentation for details. 

Note that if the input series has no missing values and no values that TRAMO regards as outliers, this function will return a copy of the original series. 

# ljungbox stats
Output: 	scalar 
Arguments:	<@var="y">  (series)
		<@var="p">  (integer)

Computes the Ljung–Box Q' statistic for the series <@var="y"> using lag order <@var="p">, over the currently defined sample range. The lag order must be greater than or equal to 1 and less than the number of available observations. 

This statistic may be referred to the chi-square distribution with <@var="p"> degrees of freedom as a test of the null hypothesis that the series <@var="y"> is not serially correlated. See also <@ref="pvalue">. 

# lngamma math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the log of the gamma function of <@var="x">. 

See also <@ref="bincoeff"> and <@ref="gammafun">. 

# loess nonparam
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="x">  (series)
		<@var="d">  (integer, optional)
		<@var="q">  (scalar, optional)
		<@var="robust">  (boolean, optional)

Performs locally-weighted polynomial regression and returns a series holding predicted values of <@var="y"> for each non-missing value of <@var="x">. The method is as described by <@bib="William Cleveland (1979);cleveland79">. 

The optional arguments <@var="d"> and <@var="q"> specify the order of the polynomial in <@var="x"> and the proportion of the data points to be used in local estimation, respectively. The default values are <@var="d"> = 1 and <@var="q"> = 0.5. The other acceptable values for <@var="d"> are 0 and 2. Setting <@var="d"> = 0 reduces the local regression to a form of moving average. The value of <@var="q"> must be greater than 0 and cannot exceed 1; larger values produce a smoother outcome. 

If a non-zero value is given for the <@var="robust"> argument the local regressions are iterated twice, with the weights being modified based on the residuals from the previous iteration so as to give less influence to outliers. 

See also <@ref="nadarwat">, and in addition see chapter 40 of the <@pdf="Gretl User's Guide#chap:nonparam"> for details on nonparametric methods. 

# log math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series, matrix or list)

Returns the natural logarithm of <@var="x">; produces <@lit="NA"> for non-positive values. Note: <@lit="ln"> is an acceptable alias for <@lit="log">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="l_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

Note that in case of matrix input the function acts element by element. For the matrix logarithm function, see <@ref="mlog">. 

# log10 math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the base-10 logarithm of <@var="x">; produces <@lit="NA"> for non-positive values. 

# log2 math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the base-2 logarithm of <@var="x">; produces <@lit="NA"> for non-positive values. 

# logistic math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the logistic CDF of the argument <@var="x">, that is, 1/(1 + <@mth="e"><@sup="–x">). If <@var="x"> is a matrix, the function is applied element by element. 

# lpsolve math
Output: 	bundle 
Argument: 	<@var="specs">  (bundle)

Solves a linear programming problem using the lpsolve library. See <@adb="gretl-lpsolve.pdf"> for details and examples of usage. 

# lower matrix
Output: 	square matrix 
Argument: 	<@var="A">  (matrix)

Returns an <@itl="n">×<@itl="n"> lower triangular matrix: the elements on and below the diagonal are equal to the corresponding elements of <@var="A">; the remaining elements are zero. 

See also <@ref="upper">. 

# lrcovar timeseries
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="demean">  (boolean, optional)

Returns the long-run variance-covariance matrix of the columns of <@var="A">. The data are first demeaned unless the second (optional) argument is set to zero. The kernel type and lag truncation parameter (window size) can be chosen before calling this function with the HAC-related options that the <@xrf="set"> command offers, such as <@lit="hac_kernel">, <@lit="hac_lag">, <@lit="hac_prewhiten">. See also the section on Time series data and HAC covariance matrices in chapter 22 of the <@pdf="Gretl User's Guide#chap:robust_vcv">. 

See also <@ref="lrvar">. 

# lrvar timeseries
Output: 	scalar 
Arguments:	<@var="y">  (series or vector)
		<@var="k">  (integer, optional)
		<@var="mu">  (scalar, optional)

Returns the long-run variance of <@var="y">, calculated using a Bartlett kernel with window size <@var="k">. If the second argument is omitted, or given a negative value, the window size defaults to the integer part of the cube root of the sample size. 

For the variance calculation, the series <@var="y"> is centered around the optional parameter <@var="mu">; if this is omitted or <@lit="NA">, the sample mean is used. 

For a multivariate counterpart, see <@ref="lrcovar">. 

# Lsolve linalg
Output: 	matrix 
Arguments:	<@var="L">  (matrix)
		<@var="b">  (matrix)

Solves for <@mth="x"> in <@mth="Ax = b">, where <@var="L"> is the lower triangular Cholesky factor of the positive definite matrix <@mth="A">, satisfying <@mth="LL' = A">. Suitable <@var="L"> can be obtained using the <@ref="cholesky"> function with <@mth="A"> as argument. 

The following two calculations should produce the same result (up to machine precision), but the first variant allows for reuse of a precomputed Cholesky factor and so should be substantially faster if you are solving repeatedly for given <@mth="A"> and several values of <@mth="b">. The speed-up will be greater, the greater the column dimension of <@mth="A">. 

<code>          
     # variant 1
     matrix L = cholesky(A)
     matrix x = Lsolve(L, b)
     # variant 2
     matrix x = A \ b
</code>

# mat2list data-utils
Output: 	list 
Arguments:	<@var="X">  (matrix)
		<@var="prefix">  (string, optional)

A convenience function for making a list of series using the columns of a suitable matrix as input. The row dimension of <@var="X"> must equal either the length of the current dataset or the number of observations in the current sample range. 

The naming of the series in the returned list proceeds as follows. First, if the optional <@var="prefix"> argument is supplied, the series created from column <@mth="i"> of <@var="X"> is named by appending <@mth="i"> to the given string, as in <@lit="myprefix1">, <@lit="myprefix2"> and so on. Otherwise, if <@var="X"> has column names set (see <@ref="cnameset">) these names are used. Finally, if neither of the above conditions is satisfied, the names are <@lit="column1">, <@lit="column2"> and so on. 

Here is an illustrative example of usage: 

<code>          
     matrix X = mnormal($nobs, 8)
     list L = mat2list(X, "xnorm")
     # or alternatively, if you don't need X as such
     list L = mat2list(mnormal($nobs, 8), "xnorm")
</code>

This will add to the dataset eight full-length series named <@lit="xnorm1">, <@lit="xnorm2"> and so on. 

# max stats
Output: 	scalar or series 
Argument: 	<@var="y">  (series or list)

If the argument <@var="y"> is a series, returns the (scalar) maximum of the non-missing observations in the series. If the argument is a list, returns a series each of whose elements is the maximum of the values of the listed variables at the given observation. 

See also <@ref="min">, <@ref="xmax">, <@ref="xmin">. 

# maxc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns a row vector containing the maxima of the columns of <@var="X">. 

See also <@ref="imaxc">, <@ref="maxr">, <@ref="minc">. 

# maxr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns a column vector containing the maxima of the rows of <@var="X">. 

See also <@ref="imaxr">, <@ref="maxc">, <@ref="minr">. 

# mcorr stats
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Computes a (Pearson) correlation matrix treating each column of <@var="X"> as a variable. See also <@ref="corr">, <@ref="cov">, <@ref="mcov">. 

# mcov stats
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="dfcorr">  (integer, optional)

Computes a covariance matrix treating each column of <@var="X"> as a variable. The divisor is <@mth="n"> – 1, where <@mth="n"> is the number of rows of <@var="X">, unless the optional argument <@var="dfcorr"> is 0, in which case <@mth="n"> is used. 

See also <@ref="corr">, <@ref="cov">, <@ref="mcorr">. 

# mcovg stats
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="u">  (vector, optional)
		<@var="w">  (vector, optional)
		<@var="p">  (integer)

Returns the matrix covariogram for a <@itl="T">×<@itl="k"> matrix <@var="X"> (typically containing regressors), an (optional) <@mth="T ">-vector <@var="u"> (typically containing residuals), an (optional) (<@mth="p">+1)-vector of weights <@var="w">, and a lag order <@var="p">, which must be greater than or equal to 0. 

The returned matrix is the sum for <@mth="j"> from <@mth="-p"> to <@mth="p"> of <@mth="w(|j|) * X(t)X(t-j)' * u(t)u(t-j)">, where <@mth="X(t)'"> is the <@mth="t">-th row of <@var="X">. 

If <@var="u"> is given as <@lit="null"> the <@mth="u"> terms are omitted, and if <@var="w"> is given as <@lit="null"> all the weights are taken to be 1.0. 

For example, the following piece of code 

<code>          
     set seed 123
     X = mnormal(6,2)
     Lag = mlag(X,1)
     Lead = mlag(X,-1)
     print X Lag Lead
     eval X'X
     eval mcovg(X, , , 0)
     eval X'(X + Lag + Lead)
     eval mcovg(X, , , 1)
</code>

produces this output: 

<code>          
     ? print X Lag Lead
     X (6 x 2)

       -0.76587      -1.0600
       -0.43188      0.30687
       -0.82656      0.40681
        0.39246      0.75479
        0.36875       2.5498
        0.28855     -0.55251

     Lag (6 x 2)

         0.0000       0.0000
       -0.76587      -1.0600
       -0.43188      0.30687
       -0.82656      0.40681
        0.39246      0.75479
        0.36875       2.5498

     Lead (6 x 2)

       -0.43188      0.30687
       -0.82656      0.40681
        0.39246      0.75479
        0.36875       2.5498
        0.28855     -0.55251
         0.0000       0.0000

     ? eval X'X
         1.8295       1.4201
         1.4201       8.7596

     ? eval mcovg(X,,, 0)
         1.8295       1.4201
         1.4201       8.7596

     ? eval X'(X + Lag + Lead)
         3.0585       2.5603
         2.5603       10.004

     ? eval mcovg(X,,, 1)
         3.0585       2.5603
         2.5603       10.004
</code>

# mean stats
Output: 	scalar or series 
Arguments:	<@var="x">  (series or list)
		<@var="partial">  (boolean, optional)

If <@var="x"> is a series, returns the (scalar) sample mean, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the mean of the values of the variables in the list at observation <@mth="t">. By default the mean is recorded as <@lit="NA"> if there are any missing values at <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used to form the statistic. 

The following example illustrates the working of the function 

<code>          
   	open denmark.gdt
   	eval mean(LRM)
   	list L = dataset
   	eval mean(L)
</code>

The first call will return the scalar mean value (scalar) of the series <@lit="LRM">, and the second one returns a series. 

See also <@ref="median">, <@ref="sum">, <@ref="max">, <@ref="min">, <@ref="sd">, <@ref="var">. 

# meanc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the means of the columns of <@var="X">, not skipping any missing observations. 

For example, the following piece of code 

<code>          
   	matrix m = mnormal(5, 2)
   	m[1,2] = NA
   	print m
   	eval meanc(m)
</code>

produces this output: 

<code>          
   	? print m
   	m (5 x 2)

      -0.098299          nan
         1.1829      -1.2817
        0.46037     -0.92947
         1.4896     -0.91970
        0.91918      0.47748

   	? eval meanc(m)
        0.79075          nan
</code>

See also <@ref="meanr">, <@ref="sumc">, <@ref="maxc">, <@ref="minc">, <@ref="sdc">, <@ref="prodc">. 

# meanr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the means of the rows of <@var="X">. See also <@ref="meanc">, <@ref="sumr">. 

# median stats
Output: 	scalar or series 
Argument: 	<@var="x">  (series or list)

If <@var="x"> is a series, returns the (scalar) sample median, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the median of the values of the variables in the list at observation <@mth="t">, or <@lit="NA"> if there are any missing values at <@mth="t">. 

The following example illustrates the working of the function 

<code>          
     set verbose off
     open denmark.gdt
     eval median(LRM)
     list L = dataset
     series m = median(L)
</code>

The first call will return the scalar median value (scalar) of the series <@lit="LRM">, and the second one returns a series. 

See also <@ref="mean">, <@ref="sum">, <@ref="max">, <@ref="min">, <@ref="sd">, <@ref="var">. 

# mexp linalg
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Computes the matrix exponential of <@var="A">. If <@var="A"> is a real matrix, algorithm 11.3.1 from <@bib="Golub and Van Loan (1996);golub96"> is used. If <@var="A"> is complex the algorithm uses eigendecomposition and <@var="A"> must be diagonalizable. 

See also <@ref="mlog">. 

# mgradient midas
Output: 	matrix 
Arguments:	<@var="p">  (integer)
		<@var="theta">  (vector)
		<@var="type">  (integer or string)

Analytical derivatives for MIDAS weights. Let <@mth="k"> denote the number of elements in the vector of hyper-parameters, <@var="theta">. This function returns a <@itl="p">×<@itl="k"> matrix holding the gradient of the vector of weights (as calculated by <@ref="mweights">) with respect to the elements of <@var="theta">. The first argument represents the desired lag order and the last argument specifies the type of parameterization. See <@lit="mweights"> for an account of the acceptable <@var="type"> values. 

See also <@ref="midasmult">, <@ref="mlincomb">, <@ref="mweights">. 

# midasmult midas
Output: 	matrix 
Arguments:	<@var="mod">  (bundle)
		<@var="cumulate">  (boolean)
		<@var="v">  (integer)

Computes MIDAS multipliers. The <@var="mod"> argument must be a bundle containing a MIDAS model, as the one produced by the <@xrf="midasreg"> command and accessible via the <@ref="$model"> keyword. The function returns a matrix with the implicit MIDAS multipliers for variable <@var="v"> in its first column and the corresponding standard errors in the second one. If the <@var="cumulate"> argument is nonzero, the multipliers are cumulated. 

Note that the returned matrix is automatically endowed with appropriate row labels, so it is suitable to be used as the first argument to the <@xrf="modprint"> command. For example, the code 

<code>          
     open gdp_midas.gdt
     list dIP = ld_indpro*
     smpl 1985:1 ;
     midasreg ld_qgdp 0 ; mds(dIP, 0, 6, 2)
     matrix ip_m = midasmult($model, 0, 1)
     modprint ip_m
</code>

produces the following output: 

<code>          
             coefficient   std. error      z       p-value
  ---------------------------------------------------------
  dIP_0      0.343146      0.0957752     3.583     0.0003   ***
  dIP_1      0.402547      0.0834904     4.821     1.43e-06 ***
  dIP_2      0.176437      0.0673776     2.619     0.0088   ***
  dIP_3      0.0601876     0.0621927     0.9678    0.3332
  dIP_4      0.0131263     0.0259137     0.5065    0.6125
  dIP_5      0.000965260   0.00346703    0.2784    0.7807
  dIP_6      0.00000       0.00000      NA        NA
</code>

See also <@ref="mgradient">, <@ref="mweights">, <@ref="mlincomb">. 

# min stats
Output: 	scalar or series 
Argument: 	<@var="y">  (series or list)

If the argument <@var="y"> is a series, returns the (scalar) minimum of the non-missing observations in the series. If the argument is a list, returns a series each of whose elements is the minimum of the values of the listed variables at the given observation. 

See also <@ref="max">, <@ref="xmax">, <@ref="xmin">. 

# minc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the minima of the columns of <@var="X">. 

See also <@ref="iminc">, <@ref="maxc">, <@ref="minr">. 

# minr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the minima of the rows of <@var="X">. 

See also <@ref="iminr">, <@ref="maxr">, <@ref="minc">. 

# missing data-utils
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or list)

Returns a binary variable holding 1 if <@var="x"> is <@lit="NA">. If <@var="x"> is a series, the comparison is done element by element; if <@var="x"> is a list of series, the output is a series with 1 at observations for which at least one series in the list has a missing value, and 0 otherwise. For example, the following code 

<code>          
   	nulldata 3
   	series x = normal()
   	x[2] = NA
   	series x_ismiss = missing(x)
   	print x x_ismiss --byobs
</code>

sets a missing value at the second observation of <@var="x">, and creates a new boolean series <@var="x_ismiss"> which identifies the missing observation 

<code>          
   	             y     y_ismiss

   	1    -1.551247            0
   	2                         1
   	3    -2.244616            0
</code>

See also <@ref="misszero">, <@ref="ok">, <@ref="zeromiss">. 

# misszero data-utils
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or series)

Converts <@lit="NA">s to zeros. If <@var="x"> is a series, the conversion is done element by element. For example, the following code 

<code>          
   	nulldata 3
   	series x = normal()
   	x[2] = NA
   	y = misszero(x)
   	print x y --byobs
</code>

sets a missing value at the second observation of <@var="x">, and creates a new series <@var="y"> for which the missing observation is replaced by zero: 

<code>          
                x            y

   	1    0.7355250    0.7355250
   	2                     0.000
   	3   -0.2465936   -0.2465936
</code>

See also <@ref="missing">, <@ref="ok">, <@ref="zeromiss">. 

# mlag matrix
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="p">  (scalar or vector)
		<@var="m">  (scalar, optional)

Shifts up or down the rows of <@var="X">. If <@var="p"> is a positive scalar, returns a matrix in which the columns of <@var="X"> are shifted down by <@var="p"> rows and the first <@var="p"> rows are filled with the value <@var="m">. If <@var="p"> is a negative number, <@var="X"> is shifted up and the last rows are filled with the value <@var="m">. If <@var="m"> is omitted, it is understood to be zero. 

If <@var="p"> is a vector the operation described above is carried out for each element in <@var="p"> and the resulting matrices are joined horizontally. The following code illustrates this usage, for input <@var="X"> with two columns and input <@var="p"> calling for lags 1 and 2. Missing values are set to NA as opposed to the default of 0. 

<code>          
   matrix X = mnormal(5, 2)
   print X
   eval mlag(X, {1, 2}, NA)
</code>

<code>      
   m (5 x 2)

      1.5953    -0.070740
    -0.52713     -0.47669
     -2.2056     -0.28112
     0.97753       1.4280
     0.49654      0.18532

         nan          nan          nan          nan
      1.5953    -0.070740          nan          nan
    -0.52713     -0.47669       1.5953    -0.070740
     -2.2056     -0.28112     -0.52713     -0.47669
     0.97753       1.4280      -2.2056     -0.28112
</code>

See also <@ref="lags">. 

# mlincomb midas
Output: 	series 
Arguments:	<@var="hfvars">  (list)
		<@var="theta">  (vector)
		<@var="type">  (integer or string)

A convenience MIDAS function which combines <@ref="lincomb"> with <@ref="mweights">. Given a list <@var="hfvars">, it constructs a series which is a weighted sum of the elements of the list, the weights based on the vector of hyper-parameters <@var="theta"> and the type of parameterization: see <@lit="mweights"> for details. Note that <@ref="hflags"> is generally the best way to create a list suitable as the first argument to this function. 

To be explicit, the call 

<code>          
     series s = mlincomb(hfvars, theta, 2)
</code>

is equivalent to 

<code>          
     matrix w = mweights(nelem(hfvars), theta, 2)
     series s = lincomb(hfvars, w)
</code>

but use of <@lit="mlincomb"> saves on some typing and also some CPU cycles. 

# mlog linalg
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Computes the matrix logarithm of <@var="A">. The algorithm employed relies on eigendecomposition, which requires that <@var="A"> be diagonalizable. See also <@ref="mexp">. 

# mnormal matrix
Output: 	matrix 
Arguments:	<@var="r">  (integer)
		<@var="c">  (integer, optional)

Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with standard normal pseudo-random variates. If omitted, the number of columns defaults to 1 (column vector). See also <@ref="normal">, <@ref="muniform">. 

# mols stats
Output: 	matrix 
Arguments:	<@var="Y">  (matrix)
		<@var="X">  (matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)
		<@var="&V">  (reference to matrix, or <@lit="null">)

Returns a <@itl="k">×<@itl="n"> matrix of parameter estimates obtained by OLS regression of the <@itl="T">×<@itl="n"> matrix <@var="Y"> on the <@itl="T">×<@itl="k"> matrix <@var="X">. 

If the third argument is not <@lit="null">, the <@itl="T">×<@itl="n"> matrix <@var="U"> will contain the residuals. If the final argument is given and is not <@lit="null"> then the <@itl="k">×<@itl="k"> matrix <@var="V"> will contain (a) the covariance matrix of the parameter estimates, if <@var="Y"> has just one column, or (b) <@mth="X'X"><@sup="-1"> if <@var="Y"> has multiple columns. 

By default, estimates are obtained via Cholesky decomposition, with a fallback to QR decomposition if the columns of <@var="X"> are highly collinear. The use of SVD can be forced via the command <@lit="set svd on">. 

See also <@ref="mpols">, <@ref="mrls">. 

# monthlen calendar
Output: 	same type as input 
Arguments:	<@var="month">  (scalar or series)
		<@var="year">  (scalar or series)
		<@var="weeklen">  (integer)

Returns the number of (relevant) days in the specified month in the specified year, on the proleptic Gregorian calendar. The <@var="weeklen"> argument, which must equal 5, 6 or 7, gives the number of days in the week that should be counted (a value of 6 omits Sundays, and a value of 5 omits both Saturdays and Sundays). 

The return value is a scalar if both <@var="month"> and <@var="year"> are scalars, otherwise a series. 

For example, if you have a monthly dataset open, the call 

<code>          
     series wd = monthlen($obsminor, $obsmajor, 5)
</code>

will return a series containing the number of working days for each month in the sample. 

# movavg timeseries
Output: 	series 
Arguments:	<@var="x">  (series)
		<@var="p">  (scalar)
		<@var="control">  (integer, optional)
		<@var="y0">  (scalar, optional)

Depending on the value of the parameter <@var="p">, returns either a simple or an exponentially weighted moving average of the input series <@var="x">. 

If <@var="p"> > 1, a simple <@var="p">-term moving average is computed, that is, the arithmetic mean of <@mth="x"> from period <@mth="t"> to <@mth="t-p+1">. If a non-zero value is supplied for the optional <@var="control"> parameter the MA is centered, otherwise it is “trailing”. The optional <@var="y0"> argument is ignored. 

If <@var="p"> is a positive fraction, an exponential moving average is computed: 

<@mth="y(t) = p*x(t) + (1-p)*y(t-1)"> 

By default the output series, <@mth="y">, is initialized using the first value of <@var="x">, but the <@var="control"> parameter may be used to specify the number of initial observations that should be averaged to produce <@mth="y(0)">. A zero value for <@var="control"> indicates that all the observations should be used. Alternatively, an initializer may be specified using the optional <@var="y0"> argument; in that case the <@var="control"> argument is ignored. 

# mpiallred mpi
Output: 	integer 
Arguments:	<@var="&object">  (reference to object)
		<@var="op">  (string)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Must be called by all processes. This function works like <@ref="mpireduce"> except that all processes, not just the root process, get a copy of the “reduced” object in place of the original. It is therefore equivalent to <@lit="mpireduce"> followed by a call to <@ref="mpibcast">, but more efficient. 

# mpibarrier mpi
Output: 	integer 

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Takes no arguments. Enforces synchronization of MPI processes: no process can continue beyond the barrier until it has been reached by all. 

<code>          
     # nobody gets past until everyone gets here
     mpibarrier()
</code>

# mpibcast mpi
Output: 	integer 
Arguments:	<@var="&object">  (reference to object)
		<@var="root">  (integer, optional)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Must be called by all processes. Broadcasts the <@var="object"> argument, which must be given in pointer form, to all processes. The object in question (a matrix, bundle, scalar, array, string or list) must be declared in all processes prior to the broadcast. No process can continue beyond a call to <@lit="mpibcast"> until all processes have successfully executed it. 

By default “root”, the source of the broadcast, is the MPI process with rank 0, but this can be adjusted via the optional second argument, which must be an integer from 0 to the number of MPI processes minus 1. 

A simple example follows. On successful completion every process will have a copy of the matrix <@lit="X"> defined at rank 0. 

<code>          
     matrix X
     if $mpirank == 0
         X = mnormal(T, k)
     endif
     mpibcast(&X)
</code>

# mpirecv mpi
Output: 	object 
Argument: 	<@var="src">  (integer)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). See <@ref="mpisend">, with which <@lit="mpirecv"> must always be paired, for an explanation. The <@var="src"> argument specifies the rank of the process from which the object is to be received, in the range 0 to the number of MPI processes minus 1. 

# mpireduce mpi
Output: 	integer 
Arguments:	<@var="&object">  (reference to object)
		<@var="op">  (string)
		<@var="root">  (integer, optional)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Must be called by all processes. This function gathers objects (scalars, matrices or arrays) of a specified name, given in pointer form, from all processes and “reduces” them to a single object at the root node. 

The <@lit="op"> argument specifies the reduction operation or method. The methods supported for scalars are <@lit="sum">, <@lit="prod"> (product), <@lit="max"> and <@lit="min">. For matrices the methods are <@lit="sum">, <@lit="prod"> (Hadamard product), <@lit="hcat"> (horizontal concatenation) and <@lit="vcat"> (vertical concatenation). For arrays only <@lit="acat"> (concatenation) is supported. 

By default “root”, the target of the reduction, is the MPI process with rank 0, but this can be adjusted via the optional third argument, which must be an integer from 0 to the number of MPI processes minus 1. 

An example follows. On successful completion of the above, the root process will have a matrix <@lit="X"> which is the sum of the matrices <@lit="X"> at all processes. 

<code>          
     matrix X
     X = mnormal(T, k)
     mpireduce(&X, sum)
</code>

# mpiscatter mpi
Output: 	integer 
Arguments:	<@var="&M">  (reference to matrix)
		<@var="op">  (string)
		<@var="root">  (integer, optional)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Must be called by all processes. This function distributes chunks of a matrix in the root process to all processes. The matrix must be declared in all processes prior to the call to <@lit="mpiscatter">, and must be given in pointer form. 

The <@lit="op"> argument must be either <@lit="byrows"> or <@lit="bycols">. Let <@mth="q"> denote the quotient of the number of rows in the matrix to be scattered and the number of processes. In the <@lit="byrows"> case root sends the first <@mth="q"> rows to process 0, the next <@mth="q"> to process 1, and so on. If there is a remainder from the division of rows it is added to the last allotment. The <@lit="bycols"> case is exactly analogous but splitting of the matrix is by columns. 

An example follows. If there are 4 processes, each one (including root) will each get a 2500×10 share of the original <@lit="X"> as it existed in the root process. If you want to preserve the full matrix in the root process, it is necessary to make a copy of it before calling <@lit="mpiscatter">. 

<code>          
     matrix X
     if $mpirank == 0
         X = mnormal(10000, 10)
     endif
     mpiscatter(&X, byrows)
</code>

# mpisend mpi
Output: 	integer 
Arguments:	<@var="object">  (object)
		<@var="dest">  (integer)

Available only when gretl is in MPI mode (see <@mnu="gretlMPI">). Sends the named object (a matrix, bundle, array, scalar, string or list) from the current process to the one identified by the integer <@var="dest"> (from 0 to the number of MPI processes minus 1). 

A call to this function must always be paired with a call to <@ref="mpirecv"> in the <@var="dest"> process, as in the following example which sends a matrix from rank 2 to rank 3. 

<code>          
     if $mpirank == 2
         matrix C = cholesky(A)
         mpisend(C, 3)
     elif $mpirank == 3
         matrix C = mpirecv(2)
     endif
</code>

# mpols stats
Output: 	matrix 
Arguments:	<@var="Y">  (matrix)
		<@var="X">  (matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)

Works exactly as <@ref="mols">, except that the calculations are done in multiple precision using the GMP library. 

By default GMP uses 256 bits for each floating point number, but you can adjust this using the environment variable <@lit="GRETL_MP_BITS">, e.g. <@lit="GRETL_MP_BITS=1024">. 

# mrandgen matrix
Output: 	matrix 
Arguments:	<@var="d">  (string)
		<@var="p1">  (scalar or matrix)
		<@var="p2">  (scalar or matrix, conditional)
		<@var="p3">  (scalar, conditional)
		<@var="rows">  (integer)
		<@var="cols">  (integer)
Examples: 	<@lit="matrix mx = mrandgen(u, 0, 100, 50, 1)">
		<@lit="matrix mt14 = mrandgen(t, 14, 20, 20)">

Works like <@ref="randgen"> except that the return value is a matrix rather than a series. The initial arguments to this function (the number of which depends on the selected distribution) are as described for <@lit="randgen">, but they must be followed by two integers to specify the number of rows and columns of the desired random matrix. If <@var="p1"> or <@var="p2"> are given in matrix form they must have a number of elements equal to the product of <@var="rows"> and <@var="cols">. 

The first example above calls for a uniform random column vector of length 50, while the second example specifies a 20×20 random matrix with drawings from the <@mth="t"> distribution with 14 degrees of freedom. 

See also <@ref="mnormal">, <@ref="muniform">. 

# mread data-utils
Output: 	matrix 
Arguments:	<@var="fname">  (string)
		<@var="import">  (boolean, optional)

Reads a matrix from a file named <@var="fname">. If the file name does not contain a full path specification, it will be looked for in several “likely” locations, beginning with the currently set <@xrf="workdir">. However, if a non-zero value is given for the optional <@var="import"> argument, the input file is looked for in the user's “dot” directory. This is intended for use with the matrix-exporting functions offered in the context of the <@xrf="foreign"> command. In this case the <@var="fname"> argument should be a plain filename, without any path component. 

Currently, the function recognizes four file formats: 

<@itl="Native text format"> 

These files are identified by the extension “<@lit=".mat">”, and are fully compatible with the Ox matrix file format. If the filename has the suffix “<@lit=".gz">” it is assumed that gzip compression has been applied in writing the data. The file is assumed to be plain text, conforming to the following specification: 

<indent>
• It starts with zero or more comments, defined as lines that start with the hash mark, <@lit="#">; such lines are ignored. 
</indent>

<indent>
• The first non-comment line contains two integers, separated by a tab character, indicating the number of rows and columns, respectively. 
</indent>

<indent>
• The columns are separated by tabs. 
</indent>

<indent>
• The decimal separator is the dot character, “<@lit=".">”. 
</indent>

<@itl="Binary files"> 

Files with the suffix “<@lit=".bin">” are assumed to be in binary format. The “<@lit=".gz">” suffix, for gzip compression, is also recognized. The first 19 bytes contain the characters <@lit="gretl_binary_matrix">, the next 8 bytes contain two 32-bit integers giving the number of rows and columns, and the remainder of the file contains the matrix elements as little-endian “doubles”, in column-major order. If gretl is run on a big-endian system, the binary values are converted to little endian on writing, and converted to big endian on reading. 

<@itl="Delimited text files"> 

If the name of the file to be read has extension “<@lit=".csv">” the rules governing the format of the file are different, and more relaxed. In this case the actual data should <@itl="not"> be preceded by a line giving the number of rows and columns. Gretl will try to figure out the delimiter (comma, semicolon or space) and do its best to import the matrix, allowing for use of comma as decimal separator if need be. Note that the delimiter should not be the tab character, on pain of confusing such files with those in gretl's “native” matrix format. 

<@itl="Gretl dataset files"> 

Files with extension “<@lit=".gdt">” or “<@lit=".gdtb">” are treated as gretl native data files, as created by the <@xrf="store"> command. In this case, the matrix returned contains the numerical values of the series of the dataset, arranged by column. Note that string-valued series are not read as such; the matrix will just contain their numeric encodings. 

See also <@ref="bread">, <@ref="mwrite">. 

# mreverse matrix
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="bycol">  (boolean, optional)

Returns a matrix containing the rows of <@var="X"> in reverse order, or the columns in reverse order if the optional second argument has a non-zero value. 

# mrls stats
Output: 	matrix 
Arguments:	<@var="Y">  (matrix)
		<@var="X">  (matrix)
		<@var="R">  (matrix)
		<@var="q">  (column vector)
		<@var="&U">  (reference to matrix, or <@lit="null">)
		<@var="&V">  (reference to matrix, or <@lit="null">)

Restricted least squares: returns a <@itl="k">×<@itl="n"> matrix of parameter estimates obtained by least-squares regression of the <@itl="T">×<@itl="n"> matrix <@var="Y"> on the <@itl="T">×<@itl="k"> matrix <@var="X"> subject to the linear restriction <@mth="RB"> = <@mth="q">, where <@mth="B"> denotes the stacked coefficient vector. <@var="R"> must have <@mth="kn"> columns; each row of this matrix represents a linear restriction. The number of rows in <@var="q"> must match the number of rows in <@var="R">. 

If the fifth argument is not <@lit="null">, the <@itl="T">×<@itl="n"> matrix <@var="U"> will contain the residuals. If the final argument is given and is not <@lit="null"> then the <@itl="k">×<@itl="k"> matrix <@var="V"> will hold the restricted counterpart to the matrix <@mth="X'X"><@sup="-1">. The variance matrix of the estimates for equation <@mth="i"> can be constructed by multiplying the appropriate sub-matrix of <@var="V"> by an estimate of the error variance for that equation. 

# mshape matrix
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="r">  (integer)
		<@var="c">  (integer, optional)

Rearranges the elements of <@var="X"> into a matrix with <@var="r"> rows and <@var="c"> columns. Elements are read from <@var="X"> and written to the target in column-major order. If <@var="X"> contains fewer than <@mth="k"> = <@mth="rc"> elements, the elements are repeated cyclically; otherwise, if <@var="X"> has more elements, only the first <@mth="k"> are used. 

If the third argument is omitted, <@var="c"> defaults to 1 if <@var="X"> is 1×1 otherwise to <@mth="N">/<@var="r"> where <@mth="N"> is the total number of elements in <@var="X">. However, if <@mth="N"> is not an integer multiple of <@var="r"> an error is flagged. 

See also <@ref="cols">, <@ref="rows">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# msortby matrix
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="j">  (integer)

Returns a matrix in which the rows of <@var="X"> are reordered by increasing value of the elements in column <@var="j">. This is a stable sort: rows that share the same value in column <@var="j"> will not be interchanged. 

# msplitby matrix
Output: 	array of matrices 
Arguments:	<@var="X">  (matrix)
		<@var="v">  (scalar or matrix)
		<@var="bycol">  (boolean)

Returns an array of matrices, the result of splitting <@var="X"> horizontally or vertically under the control of the arguments <@var="v"> and <@var="bycol">. If <@var="bycol"> is nonzero, the matrix will be split by columns; otherwise, as per default, by rows. 

The argument <@var="v"> can be either a vector or a scalar. In the former case, the vector must be of length equal to the relevant (row or column) dimension of <@var="X">, and should contain integer values with a minimum of 1 and a maximum equal to the number of matrices in the desired array. Each element of <@var="v"> indicates the array index of the matrix to which the corresponding row of <@var="X"> should be assigned. If, instead, <@var="v"> is a scalar, then <@var="X"> will be split in chunks with <@var="v"> rows/columns each (as dictated by <@var="bycol">); an error will be flagged if the relevant matrix dimension is not an exact multiple of <@var="v">. 

In the following example we split a 4×3 matrix into three matrices: the first two rows are assigned to the first matrix; the second matrix is left empty; the third and fourth matrices gets row 3 and 4 of <@var="X">, respectively 

<code>          
     matrix X = {1,2,3; 4,5,6; 7,8,9; 10,11,12}
     matrices M = msplitby(X, {1,1,3,4})
     print M
</code>

The print statement gives 

<code>          
     Array of matrices, length 4
     [1] 2 x 3
     [2] null
     [3] 1 x 3
     [4] 1 x 3
</code>

The next example splits <@var="X"> evenly: 

<code>          
     matrix X = {1,2,3; 4,5,6; 7,8,9; 10,11,12}
     matrices MM = msplitby(X, 2)
     print MM[1]
     print MM[2]
</code>

which gives 

<code>          
     ? print MM[1]
     1   2   3 
     4   5   6 

     ? print MM[2]
     7    8    9 
     10   11   12
</code>

See <@ref="flatten"> for the inverse operation. 

# muniform matrix
Output: 	matrix 
Arguments:	<@var="r">  (integer)
		<@var="c">  (integer, optional)

Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with uniform (0,1) pseudo-random variates. If omitted, the number of columns defaults to 1 (column vector). Note: the preferred method for generating a scalar uniform r.v. is to use the <@ref="randgen1"> function. 

See also <@ref="mnormal">, <@ref="uniform">. 

# mweights midas
Output: 	matrix 
Arguments:	<@var="p">  (integer)
		<@var="theta">  (vector)
		<@var="type">  (integer or string)

Returns a <@mth="p">-vector of MIDAS weights to be applied to <@mth="p"> lags of a high-frequency series, based on the vector <@var="theta"> of hyper-parameters. 

The <@var="type"> argument identifies the type of parameterization, which governs the required number of elements, <@mth="k">, in <@var="theta">: 1 = normalized exponential Almon (<@mth="k"> at least 1, typically 2); 2 = normalized beta with zero last (<@mth="k"> = 2); 3 = normalized beta with non-zero last lag (<@mth="k"> = 3); and 4 = Almon polynomial (<@mth="k"> at least 1). Note that in the normalized beta case the first two elements of <@var="theta"> must be positive. 

The <@var="type"> may be given as an integer code, as shown above, or by one of the following strings (respectively): <@lit="nealmon">, <@lit="beta0">, <@lit="betan">, <@lit="almonp">. If a string is used, it should be placed in double quotes. For example, the following two statements are equivalent: 

<code>          
     W = mweights(8, theta, 2)
     W = mweights(8, theta, "beta0")
</code>

See also <@ref="mgradient">, <@ref="midasmult">, <@ref="mlincomb">. 

# mwrite data-utils
Output: 	integer 
Arguments:	<@var="X">  (matrix)
		<@var="fname">  (string)
		<@var="export">  (boolean, optional)

Writes the matrix <@var="X"> to a file named <@var="fname">. By default this file will be plain text; the first line will hold two integers, separated by a tab character, representing the number of rows and columns; on the following lines the matrix elements appear, in scientific notation, separated by tabs (one line per row). To avoid confusion on reading, files to be written in this format should be named with the suffix “<@lit=".mat">”. See below for alternative formats. 

If a file <@var="fname"> already exists, it will be overwritten. The nominal return value is 0 on successful completion; if writing fails an error is flagged. 

The output file will be written in the currently set <@xrf="workdir">, unless the <@var="filename"> string contains a full path specification. However, if a non-zero value is given for the <@var="export"> argument, the output file will be written into the user's “dot” directory, where it is accessible by default via the matrix-loading functions offered in the context of the <@xrf="foreign"> command. In this case a plain filename, without any path component, should be given for the second argument. 

Matrices stored via the <@lit="mwrite"> function in its default form can be easily read by other programs; see chapter 17 of the <@pdf="Gretl User's Guide#chap:matrices"> for details. 

Three mutually exclusive inflections of this function are available, as follows: 

<indent>
• If <@var="fname"> has the suffix “<@lit=".gz">” then the file is written in the format described above but with gzip compression. 
</indent>

<indent>
• If <@var="fname"> has the suffix “<@lit=".bin">” then the matrix is written in binary format. In this case the first 19 bytes contain the characters <@lit="gretl_binary_matrix">, the next 8 bytes contain two 32-bit integers giving the number of rows and columns, and the remainder of the file contains the matrix elements as little-endian “doubles”, in column-major order. If gretl is run on a big-endian system, the binary values are converted to little endian on writing, and converted to big endian on reading. 
</indent>

<indent>
• If <@var="fname"> has the suffix “<@lit=".csv">” then the matrix is written in comma-separated format, without a header line indicating the number of rows and columns to follow. This may be easier for third-party programs to handle, but it is not recommended if the matrix file is intended for reading by gretl. 
</indent>

Note that if the matrix file is to be read by a third-party program it is not advisable to use the gzip or binary options. But if the file is intended for reading by gretl the alternative formats save space, and the binary format allows for much faster reading of large matrices. The gzip format is not recommended for very large matrices, since decompression can be quite slow. 

See also <@ref="mread">. And for writing a matrix to file as a dataset, see <@xrf="store">. 

# mxtab stats
Output: 	matrix 
Arguments:	<@var="x">  (series or vector)
		<@var="y">  (series or vector)

Returns a matrix holding the cross tabulation of the values contained in <@var="x"> (by row) and <@var="y"> (by column). The two arguments should be of the same type (both series or both column vectors), and because of the typical usage of this function, are assumed to contain integer values only. 

See also <@ref="values">. 

# naalen nonparam
Output: 	matrix 
Arguments:	<@var="d">  (series or vector)
		<@var="cens">  (series or vector, optional)

Given a sample of duration data, <@var="d">, possibly accompanied by a record of censoring status, <@var="cens">, computes the Nelson–Aalen nonparametric estimator of the hazard function (<@bib="Nelson, 1972;nelson72">; <@bib="Aalen, 1978;aalen78">). The returned matrix has three columns holding, respectively, the sorted unique values in <@var="d">, the estimated cumulated hazard function corresponding to the duration value in column 1, and the standard error of the estimator. 

If the <@var="cens"> series is given, the value 0 is taken to indicate an uncensored observation while a value of 1 indicates a right-censored observation (that is, the period of observation of the individual in question has ended before the duration or spell has been recorded as terminated). If <@var="cens"> is not given, it is assumed that all observations are uncensored. (Note: the semantics of <@var="cens"> may be extended at some point to cover other types of censoring.) 

See also <@ref="kmeier">. 

# nadarwat nonparam
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="x">  (series)
		<@var="h">  (scalar, optional)
		<@var="LOO">  (boolean, optional)
		<@var="trim">  (scalar, optional)

Computes the Nadaraya–Watson nonparametric estimator of the conditional mean of <@var="y"> given <@var="x">. The return value is a series holding <@mth="m(x"><@sub="i"><@mth=")">, the estimate of <@mth="E(y"><@sub="i"><@mth="|x"><@sub="i"><@mth=")"> for each non-missing element of the series <@var="x">. 

The kernel function employed by this estimator is given by <@mth="K = exp(-x"><@sup="2"><@mth=" / 2h)"> for <@mth="|x| < T">, and zero otherwise. (<@mth="T"> = trimming parameter.) 

The three optional arguments inflect the behavior of the estimator as described below. 

<@itl="Bandwidth"> 

The argument <@var="h"> can be used to control the bandwidth, a positive real number. This is usually small; larger values of <@var="h"> make <@mth="m(x)"> smoother. A popular choice is to make <@var="h"> proportional to <@mth="n"><@sup="-0.2">. If <@var="h"> is omitted or set to zero, the bandwidth defaults to a data-determined value using the proportionality just mentioned but incorporating the dispersion of the <@var="x"> data as measured by the inter-quartile range or standard deviation; see chapter 40 of the <@pdf="Gretl User's Guide#chap:nonparam"> for more details. 

<@itl="Leave-one-out"> 

“Leave-one-out” is a variant of the algorithm which omits the <@mth="i">-th observation when evaluating <@mth="m(x"><@sub="i"><@mth=")">. This makes the Nadaraya–Watson estimator more robust numerically and is generally advised when the estimator is computed for inference purposes. This variant is not enabled by default, but is activated if a non-zero value is given for the <@var="LOO"> argument. 

<@itl="Trimming"> 

The <@var="trim"> argument can be used to control the degree of “trimming”, which is imposed to prevent numerical problems when the kernel function is evaluated too far away from zero. This parameter is expressed as a multiple of <@var="h">, the default value being 4. In some cases a value greater than 4 may be preferable. Again see chapter 40 of the <@pdf="Gretl User's Guide#chap:nonparam"> for details. 

See also <@ref="loess">. 

# nelem data-utils
Output: 	integer 
Argument: 	<@var="L">  (list, matrix, bundle or array)

Returns the number of elements in the argument, which may be a list, a matrix, a bundle, or an array (but not a series). 

# ngetenv programming
Output: 	scalar 
Argument: 	<@var="s">  (string)

If an environment variable by the name of <@var="s"> is defined and has a numerical value, returns that value; otherwise returns NA. See also <@ref="getenv">. 

# nlines strings
Output: 	scalar 
Argument: 	<@var="buf">  (string)

Returns a count of the complete lines (that is, lines that end with the newline character) in <@var="buf">. 

Example: 

<code>          
        string web_page = readfile("http://gretl.sourceforge.net/")
        scalar number = nlines(web_page)
        print number
</code>

# NMmax numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="f">  (function call)
		<@var="maxfeval">  (integer, optional)

Numerical maximization via the Nelder–Mead derivative-free simplex method. On input the vector <@var="b"> should hold the initial values of a set of parameters, and the argument <@var="f"> should specify a call to a function that calculates the (scalar) criterion to be maximized, given the current parameter values and any other relevant data. On successful completion, <@lit="NMmax"> returns the maximized value of the criterion, and <@var="b"> holds the parameter values which produce the maximum. 

The optional third argument may be used to set the maximum number of function evaluations; if it is omitted or set to zero the maximum defaults to 2000. As a special signal to this function the <@var="maxfeval"> value may be set to a negative number. In this case the absolute value is taken, and <@lit="NMmax"> flags an error if the best value found for the objective function at the maximum number of function evaluations is not a local optimum. Otherwise non-convergence in this sense is not treated as an error. 

If the object is in fact minimization, either the function call should return the negative of the criterion or alternatively <@lit="NMmax"> may be called under the alias <@lit="NMmin">. 

For more details and examples chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. See also <@ref="simann">. 

# NMmin numerical
Output: 	scalar 

An alias for <@ref="NMmax">; if called under this name the function acts as a minimizer. 

# nobs stats
Output: 	integer 
Argument: 	<@var="y">  (series)

Returns the number of non-missing observations for the variable <@var="y"> in the currently selected sample. 

See also <@ref="pnobs">, <@ref="pxnobs">. 

# normal probdist
Output: 	series 
Arguments:	<@var="μ">  (scalar)
		<@var="σ">  (scalar)

Generates a series of Gaussian pseudo-random variates with mean μ and standard deviation σ. If no arguments are supplied, standard normal variates <@mth="N">(0,1) are produced. The values are produced using the Ziggurat method <@bib="(Marsaglia and Tsang, 2000);marsaglia00">. 

See also <@ref="randgen">, <@ref="mnormal">, <@ref="muniform">. 

# normtest stats
Output: 	matrix 
Arguments:	<@var="y">  (series or vector)
		<@var="method">  (string, optional)

Performs a test for normality of <@var="y">. By default this is the Doornik–Hansen test but the optional <@var="method"> argument can be used to select an alternative: use <@lit="swilk"> to get the Shapiro–Wilk test, <@lit="jbera"> for Jarque–Bera test, or <@lit="lillie"> for the Lilliefors test. 

The second argument may be given in either quoted or unquoted form. In the latter case, however, if the argument is the name of a string variable the value of the variable is substituted. The following shows three acceptable ways of calling for a Shapiro–Wilk test: 

<code>          
     matrix nt = normtest(y, swilk)
     matrix nt = normtest(y, "swilk")
     string testtype = "swilk"
     matrix nt = normtest(y, testtype)
</code>

The returned matrix is 1×2; it holds the test statistic and its p-value. See also the <@xrf="normtest"> command. 

# npcorr stats
Output: 	matrix 
Arguments:	<@var="x">  (series or vector)
		<@var="y">  (series or vector)
		<@var="method">  (string, optional)

Calculates a measure of correlation between <@var="x"> and <@var="y"> using a nonparametric method. If given, the third argument should be either <@lit="kendall"> (for Kendall's tau, version b, the default method) or <@lit="spearman"> (for Spearman's rho). 

The return value is a 3-vector holding the correlation measure plus a test statistic and p-value for the null hypothesis of no correlation. Note that if the sample size is too small the test statistic and/or p-value may be <@lit="NaN"> (not a number, or missing). 

See also <@ref="corr"> for Pearson correlation. 

# npv math
Output: 	scalar 
Arguments:	<@var="x">  (series or vector)
		<@var="r">  (scalar)

Returns the Net Present Value of <@var="x">, considered as a sequence of payments (negative) and receipts (positive), evaluated at annual discount rate <@var="r">, which must be expressed as a decimal fraction, not a percentage (0.05 rather than 5<@lit="%">). The first value is taken as dated “now” and is not discounted. To emulate an NPV function in which the first value is discounted, prepend zero to the input sequence. 

Supported data frequencies are annual, quarterly, monthly, and undated (undated data are treated as if annual). 

See also <@ref="irr">. 

# NRmax numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="f">  (function call)
		<@var="g">  (function call, optional)
		<@var="h">  (function call, optional)

Numerical maximization via the Newton–Raphson method. On input the vector <@var="b"> should hold the initial values of a set of parameters, and the argument <@var="f"> should specify a call to a function that calculates the (scalar) criterion to be maximized, given the current parameter values and any other relevant data. If the object is in fact minimization, this function should return the negative of the criterion. On successful completion, <@lit="NRmax"> returns the maximized value of the criterion, and <@var="b"> holds the parameter values which produce the maximum. 

The optional third and fourth arguments provide means of supplying analytical derivatives and an analytical (negative) Hessian, respectively. The functions referenced by <@var="g"> and <@var="h"> must take as their first argument a predefined matrix that is of the correct size to contain the gradient or Hessian, respectively, given in pointer form. They also must take the parameter vector as an argument (in pointer form or otherwise). Other arguments are optional. If either or both of the optional arguments are omitted, a numerical approximation is used. 

For more details and examples see chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. See also <@ref="BFGSmax">, <@ref="fdjac">. 

# NRmin numerical
Output: 	scalar 

An alias for <@ref="NRmax">; if called under this name the function acts as a minimizer. 

# nullspace linalg
Output: 	matrix 
Argument: 	<@var="A">  (matrix)

Computes the right nullspace of <@var="A">, via the singular value decomposition: the result is a matrix <@mth="B"> such that the product <@mth="AB"> is a zero matrix, except when <@var="A"> has full column rank, in which case an empty matrix is returned. Otherwise, if <@var="A"> is <@itl="m">×<@itl="n">, <@mth="B"> will be <@mth="n"> by (<@mth="n"> – <@mth="r">), where <@mth="r"> is the rank of <@var="A">. 

If <@var="A"> is not of full column rank, then the vertical concatenation of <@var="A"> and the transpose of <@var="B"> produces a full rank matrix. 

Example: 

<code>          
      A = mshape(seq(1,6),2,3)
      B = nullspace(A)
      C = A | B'

      print A B C

      eval A*B
      eval rank(C)
</code>

Produces 

<code>          
      ? print A B C
      A (2 x 3)

      1   3   5
      2   4   6

      B (3 x 1)

      -0.5
         1
      -0.5

      C (3 x 3)

         1      3      5
         2      4      6
      -0.5      1   -0.5

      ? eval A*B
      -4.4409e-16
      -4.4409e-16

      ? eval rank(C)
      3
</code>

See also <@ref="rank">, <@ref="svd">. 

# numhess numerical
Output: 	matrix 
Arguments:	<@var="b">  (column vector)
		<@var="fcall">  (function call)
		<@var="d">  (scalar, optional)

Calculates a numerical approximation to the Hessian associated with the <@mth="n">-vector <@var="b"> and the objective function specified by the argument <@var="fcall">. The function call should take <@var="b"> as its first argument (either straight or in pointer form), followed by any additional arguments that may be needed, and it should return a scalar result. On successful completion <@lit="numhess"> returns an <@itl="n">×<@itl="n"> matrix holding the Hessian, which is exactly symmetric by construction. 

The method used is Richardson extrapolation, with four steps. The optional third argument can be used to set the fraction <@mth="d"> of the parameter value used in setting the initial step size; if this argument is omitted the default is <@mth="d"> = 0.01. 

Here is an example of usage: 

<code>          
     matrix H = numhess(theta, myfunc(&theta, X))
</code>

See also <@ref="BFGSmax">, <@ref="fdjac">. 

# obs data-utils
Output: 	series 

Returns a series of consecutive integers, setting 1 at the start of the dataset. Note that the result is invariant to subsampling. This function is especially useful with time-series datasets. Note: you can write <@lit="t"> instead of <@lit="obs"> with the same effect. 

See also <@ref="obsnum">. 

# obslabel data-utils
Output: 	string or array of strings 
Argument: 	<@var="t">  (scalar or vector)

If <@var="t"> is a scalar, returns a single string, the observation label for observation <@var="t">. The inverse function is provided by <@ref="obsnum">. 

If <@var="t"> is a vector, returns an array of strings, the observation labels for the observations given by the elements of <@var="t">. 

In either case the <@var="t"> values must be integers, valid as 1-based indices of observations in the current dataset, otherwise an error is flagged. 

# obsnum data-utils
Output: 	integer 
Argument: 	<@var="s">  (string)

Returns an integer corresponding to the observation specified by the string <@mth="s">. Note that the result is invariant to subsampling. This function is especially useful with time-series datasets. For example, the following code 

<code>          
     open denmark
     k = obsnum(1980:1)
</code>

yields <@lit="k = 25">, indicating that the first quarter of 1980 is the 25th observation in the <@lit="denmark"> dataset. 

See also <@ref="obs">, <@ref="obslabel">. 

# ok data-utils
Output: 	see below 
Argument: 	<@var="x">  (scalar, series, matrix or list)

If <@var="x"> is a scalar, returns 1 if <@var="x"> is not <@lit="NA">, otherwise 0. If <@var="x"> is a series, returns a series with value 1 at observations with non-missing values and zeros elsewhere. If <@var="x"> is a list, the output is a series with 0 at observations for which at least one series in the list has a missing value, and 1 otherwise. 

If <@var="x"> is a matrix the function returns a matrix of the same dimensions as <@var="x">, with 1s in positions corresponding to finite elements of <@var="x"> and 0s in positions where the elements are non-finite (either infinities or not-a-number, as per the IEEE 754 standard). 

See also <@ref="missing">, <@ref="misszero">, <@ref="zeromiss">. But note that these functions are not applicable to matrices. 

# onenorm linalg
Output: 	scalar 
Argument: 	<@var="X">  (matrix)

Returns the 1-norm of the matrix <@var="X">, that is, the maximum across the columns of <@var="X"> of the sum of absolute values of the column elements. 

See also <@ref="infnorm">, <@ref="rcond">. 

# ones matrix
Output: 	matrix 
Arguments:	<@var="r">  (integer)
		<@var="c">  (integer, optional)

Outputs a matrix with <@mth="r"> rows and <@mth="c"> columns, filled with ones. If omitted, the number of columns defaults to 1 (column vector). 

See also <@ref="seq">, <@ref="zeros">. 

# orthdev panel
Output: 	series 
Argument: 	<@var="y">  (series)

Only applicable if the currently open dataset has a panel structure. Computes the forward orthogonal deviations for variable <@var="y">. 

This transformation is sometimes used instead of differencing to remove individual effects from panel data. For compatibility with first differences, the deviations are stored one step ahead of their true temporal location (that is, the value at observation <@mth="t"> is the deviation that, strictly speaking, belongs at <@mth="t"> – 1). That way one loses the first observation in each time series, not the last. 

See also <@ref="diff">. 

# pdf probdist
Output: 	same type as input 
Arguments:	<@var="d">  (string)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="f1 = pdf(N, -2.5)">
		<@lit="f2 = pdf(X, 3, y)">
		<@lit="f3 = pdf(W, shape, scale, y)">

Probability density function calculator. Returns the density at <@var="x"> of the distribution identified by the code <@var="d">. See <@ref="cdf"> for details of the required (scalar) arguments. The distributions supported by the <@lit="pdf"> function are the normal, Student's <@mth="t">, chi-square, <@mth="F">, Gamma, Beta, Exponential, Weibull, Laplace, Generalized Error, Binomial and Poisson. Note that for the Binomial and the Poisson what's calculated is in fact the probability mass at the specified point. For Student's <@mth="t">, chi-square, <@mth="F"> the noncentral variants are supported too. 

For the normal distribution, see also <@ref="dnorm">. 

# pergm timeseries
Output: 	matrix 
Arguments:	<@var="x">  (series or vector)
		<@var="bandwidth">  (scalar, optional)

If only the first argument is given, computes the sample periodogram for the given series or vector. If the second argument is given, computes an estimate of the spectrum of <@var="x"> using a Bartlett lag window of the given bandwidth, up to a maximum of half the number of observations (<@mth="T">/2). 

Returns a matrix with two columns and <@mth="T">/2 rows: the first column holds the frequency, ω, from 2π/<@mth="T"> to π, and the second the corresponding spectral density. 

# pexpand panel
Output: 	series 
Argument: 	<@var="v">  (vector)

Only applicable if the currently open dataset has a panel structure. Performs the inverse operation of <@ref="pshrink">. That is, given a vector of length equal to the number of individuals in the current panel sample, it returns a series in which each value is repeated <@mth="T"> times, for <@mth="T"> the time-series length of the panel. The resulting series is therefore non-time varying. 

# pmax panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the maxima of variable <@var="y"> for each cross-sectional unit (repeated for each time period). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

See also <@ref="pmin">, <@ref="pmean">, <@ref="pnobs">, <@ref="psd">, <@ref="pxsum">, <@ref="pshrink">, <@ref="psum">. 

# pmean panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the time-mean of variable <@var="y"> for each cross-sectional unit, the values being repeated for each period. Missing observations are skipped in calculating the means. 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

See also <@ref="pmax">, <@ref="pmin">, <@ref="pnobs">, <@ref="psd">, <@ref="pxsum">, <@ref="pshrink">, <@ref="psum">. 

# pmin panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the minima of variable <@var="y"> for each cross-sectional unit (repeated for each time period). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

See also <@ref="pmax">, <@ref="pmean">, <@ref="pnobs">, <@ref="psd">, <@ref="pshrink">, <@ref="psum">. 

# pnobs panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the number of valid observations of variable <@var="y"> for each cross-sectional unit (repeated for each time period). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

See also <@ref="pmax">, <@ref="pmin">, <@ref="pmean">, <@ref="psd">, <@ref="pshrink">, <@ref="psum">. 

# polroots math
Output: 	matrix 
Argument: 	<@var="a">  (vector)

Finds the roots of a polynomial. If the polynomial is of degree <@mth="p">, the vector <@var="a"> should contain <@mth="p"> + 1 coefficients in ascending order, i.e. starting with the constant and ending with the coefficient on <@mth="x"><@sup="p">. 

The return value is a complex column vector of length <@mth="p">. 

# polyfit transforms
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="q">  (integer)

Fits a polynomial trend of order <@var="q"> to the input series <@var="y"> using the method of orthogonal polynomials. The series returned holds the fitted values. 

# princomp stats
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="p">  (integer)
		<@var="covmat">  (boolean, optional)

Let the matrix <@var="X"> be <@itl="T">×<@itl="k">, containing <@mth="T"> observations on <@mth="k"> variables. The argument <@var="p"> must be a positive integer less than or equal to <@mth="k">. This function returns a <@itl="T">×<@itl="p"> matrix, <@mth="P">, holding the first <@mth="p"> principal components of <@var="X">. 

The optional third argument acts as a boolean switch: if it is non-zero the principal components are computed on the basis of the covariance matrix of the columns of <@var="X"> (the default is to use the correlation matrix). 

The elements of <@mth="P"> are computed as the sum from <@mth="i"> to <@mth="k"> of <@mth="Z"><@sub="ti"> times <@mth="v"><@sub="ji">, where <@mth="Z"><@sub="ti"> is the standardized value (or just the centered value, if the covariance matrix is used) of variable <@mth="i"> at observation <@mth="t"> and <@mth="v"><@sub="ji"> is the <@mth="j">th eigenvector of the correlation (or covariance) matrix of the <@mth="X"><@sub="i">s, with the eigenvectors ordered by decreasing value of the corresponding eigenvalues. 

See also <@ref="eigensym">. 

# prodc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the product of the elements of <@var="X">, by column. See also <@ref="prodr">, <@ref="meanc">, <@ref="sdc">, <@ref="sumc">. 

# prodr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the product of the elements of <@var="X">, by row. See also <@ref="prodc">, <@ref="meanr">, <@ref="sumr">. 

# psd panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the sample standard deviation of variable <@mth="y"> for each cross-sectional unit (with the values repeated for each time period). The denominator used is the sample size for each unit minus 1, unless the number of valid observations for the given unit is 1 (in which case 0 is returned) or 0 (in which case <@lit="NA"> is returned). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

Note: this function makes it possible to check whether a given variable (say, <@lit="X">) is time-invariant via the condition <@lit="max(psd(X)) == 0">. 

See also <@ref="pmax">, <@ref="pmin">, <@ref="pmean">, <@ref="pnobs">, <@ref="pshrink">, <@ref="psum">. 

# psdroot linalg
Output: 	square matrix 
Arguments:	<@var="A">  (symmetric matrix)
		<@var="psdcheck">  (boolean, optional)

Performs a generalized variant of the Cholesky decomposition of the matrix <@var="A">, which must be positive semidefinite (but may be singular). If the input matrix is not square an error is flagged, but symmetry is assumed and not tested; only the lower triangle of <@var="A"> is read. The result is a lower-triangular matrix <@mth="L"> which satisfies <@mth="A = LL'">. Indeterminate elements in the solution are set to zero. 

To force a check on the positive semidefiniteness of <@var="A">, give a non-zero value for the optional second argument. In that case an error is flagged if the maximum absolute value of <@mth="A – LL'"> exceeds 1.0e-8. Such a check can also be performed manually: 

<code>          
     L = psdroot(A)
     chk = maxc(maxr(abs(A - L*L')))
</code>

For the case where <@var="A"> is positive definite, see <@ref="cholesky">. 

# pshrink panel
Output: 	matrix 
Argument: 	<@var="y">  (series)

Only applicable if the current dataset has a panel structure. Returns a column vector holding the first valid observation for the series <@var="y"> for each cross-sectional unit in the panel, over the current sample range. If a unit has no valid observations for the input series it is skipped. 

This function provides a means of compacting the series returned by functions such as <@ref="pmax"> and <@ref="pmean">, in which a value pertaining to each cross-sectional unit is repeated for each time period. 

See <@ref="pexpand"> for the inverse operation. 

# psum panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

This function is applicable only if the current dataset has a panel structure. It returns a series holding the sum over time of variable <@var="y"> for each cross-sectional unit, the values being repeated for each period. Missing observations are skipped in calculating the sums. 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

See also <@ref="pmax">, <@ref="pmean">, <@ref="pmin">, <@ref="pnobs">, <@ref="psd">, <@ref="pxsum">, <@ref="pshrink">. 

# pvalue probdist
Output: 	same type as input 
Arguments:	<@var="c">  (character)
		<@var="…">  (see below)
		<@var="x">  (scalar, series or matrix)
Examples: 	<@lit="p1 = pvalue(z, 2.2)">
		<@lit="p2 = pvalue(X, 3, 5.67)">
		<@lit="p2 = pvalue(F, 3, 30, 5.67)">

<@mth="P">-value calculator. Returns <@mth="P(X > x)">, where the distribution of <@mth="X"> is determined by the character <@var="c">. Between the arguments <@var="c"> and <@var="x">, zero or more additional arguments are required to specify the parameters of the distribution; see <@ref="cdf"> for details. The distributions supported by the <@lit="pvalue"> function are the standard normal, <@mth="t">, Chi square, <@mth="F">, gamma, binomial, Poisson, Exponential, Weibull, Laplace and Generalized Error. 

See also <@ref="critical">, <@ref="invcdf">, <@ref="urcpval">, <@ref="imhof">. 

# pxnobs panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the number of valid observations of <@var="y"> in each time period (this count being repeated for each unit). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

Note that this function works in a different dimension from the <@ref="pnobs"> function. 

# pxsum panel
Output: 	series 
Arguments:	<@var="y">  (series)
		<@var="mask">  (series, optional)

Only applicable if the current dataset has a panel structure. Returns a series holding the sum of the values of <@var="y"> for each cross-sectional unit in each period (the values being repeated for each unit). 

If the optional second argument is provided then observations for which the value of <@var="mask"> is zero are ignored. 

Note that this function works in a different dimension from the <@ref="psum"> function. 

# qform linalg
Output: 	matrix 
Arguments:	<@var="x">  (matrix)
		<@var="A">  (symmetric matrix)

Computes the quadratic form <@mth="Y = xAx'">. Using this function instead of ordinary matrix multiplication guarantees more speed and better accuracy, when <@var="A"> is a generic symmetric matrix. However, in the special case when <@var="A"> is the identity matrix, the simple expression <@lit="x'x"> performs much better than <@lit="qform(x',I(rows(x))">. 

If <@var="x"> and <@var="A"> are not conformable, or <@var="A"> is not symmetric, an error is returned. 

# qlrpval probdist
Output: 	scalar 
Arguments:	<@var="X2">  (scalar)
		<@var="df">  (integer)
		<@var="p1">  (scalar)
		<@var="p2">  (scalar)

<@mth="P">-values for the test statistic from the QLR sup-Wald test for a structural break at an unknown point (see <@xrf="qlrtest">), as per <@bib="Bruce Hansen (1997);hansen97">. 

The first argument, <@var="X2">, denotes the (chi-square form of) the maximum Wald test statistic and <@var="df"> denotes its degrees of freedom. The third and fourth arguments represent, as decimal fractions of the overall estimation range, the starting and ending points of the central range of observations over which the successive Wald tests are calculated. For example if the standard approach of 15 percent trimming is adopted, you would set <@var="p1"> to 0.15 and <@var="p2"> to 0.85. 

See also <@ref="pvalue">, <@ref="urcpval">. 

# qnorm probdist
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns quantiles for the standard normal distribution. If <@var="x"> is not between 0 and 1, <@lit="NA"> is returned. See also <@ref="cnorm">, <@ref="dnorm">. 

# qrdecomp linalg
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="&R">  (reference to matrix, or <@lit="null">)
		<@var="&P">  (reference to matrix, or <@lit="null">)

Computes the “thin” QR decomposition of an <@itl="m">×<@itl="n"> matrix <@var="X"> with <@mth="m"> ≥ <@mth="n">, such that <@mth="X = QR"> where <@mth="Q"> is an <@itl="m">×<@itl="n"> orthogonal matrix and <@mth="R"> is an <@itl="n">×<@itl="n"> upper triangular matrix. The matrix <@mth="Q"> is returned directly, while <@mth="R"> can be retrieved via the optional second argument. 

If the optional third argument is supplied the decomposition employs column pivoting, and on successful completion <@var="P"> holds the final ordering of the columns in the form of a row vector. If the columns are not in fact reordered <@var="P"> will compare equal to <@ref="seq"><@lit="(1, n)">. 

See also <@ref="eigengen">, <@ref="eigensym">, <@ref="svd">. 

# quadtable stats
Output: 	matrix 
Arguments:	<@var="n">  (integer)
		<@var="type">  (integer, optional)
		<@var="a">  (scalar, optional)
		<@var="b">  (scalar, optional)

Returns an <@itl="n">×2 matrix for use with Gaussian quadrature (numerical integration). The first column holds the nodes or abscissae, the second the weights. 

The first argument specifies the number of points (rows) to compute. The second argument codes for the type of quadrature: use 1 for Gauss–Hermite (the default); 2 for Gauss–Legendre; or 3 for Gauss–Laguerre. The significance of the optional parameters <@var="a"> and <@var="b"> depends on the selected <@var="type">, as explained below. 

Gaussian quadrature is a method of approximating numerically the definite integral of some function of interest. Let the function be represented as the product <@mth="f(x)W(x)">. The types of quadrature differ in the specification of the component <@mth="W(x)">: in the Hermite case this is exp(–<@mth="x"><@sup="2">); in the Laguerre case, exp(–<@mth="x">); and in the Legendre case simply <@mth="W(x)"> = 1. 

For each specification of <@mth="W">, one can compute a set of nodes, <@mth="x"><@sub="i">, and weights, <@mth="w"><@sub="i">, such that the sum from <@mth="i">=1 to <@mth="n"> of <@mth="w"><@sub="i"> <@mth="f">(<@mth="x"><@sub="i">) approximates the desired integral. The method of <@bib="Golub and Welsch (1969);golub69"> is used. 

When the Gauss–Legendre type is selected, the optional arguments <@var="a"> and <@var="b"> can be used to control the lower and upper limits of integration, the default values being –1 and 1. (In Hermite quadrature the limits are fixed at minus and plus infinity, while in the Laguerre case they are fixed at 0 and infinity.) 

In the Hermite case <@var="a"> and <@var="b"> play a different role: they can be used to replace the default form of <@mth="W">(<@mth="x">) with the (closely related) normal distribution with mean <@var="a"> and standard deviation <@var="b">. Supplying values of 0 and 1 for these parameters, for example, has the effect of making <@mth="W">(<@mth="x">) into the standard normal pdf, which is equivalent to multiplying the default nodes by the square root of two and dividing the weights by the square root of π. 

# quantile stats
Output: 	scalar or matrix 
Arguments:	<@var="y">  (series or matrix)
		<@var="p">  (scalar between 0 and 1)

If <@var="y"> is a series, returns the <@var="p">-quantile for the series. For example, when <@mth="p"> = 0.5, the median is returned. 

If <@var="y"> is a matrix, returns a row vector containing the <@var="p">-quantiles for the columns of <@var="y">; that is, each column is treated as a series. 

In addition, for matrix <@var="y"> an alternate form of the second argument is supported: <@var="p"> may be given as a vector. In that case the return value is an <@itl="m">×<@itl="n"> matrix, where <@var="m"> is the number of elements in <@var="p"> and <@var="n"> is the number of columns in <@var="y">. 

<@bib="Hyndman and Fan (1996);hyndman96"> describe nine variant methods for calculating sample quantiles. The default method in gretl is the one they call <@mth="Q"><@sub="6"> (which is also the default in Python). Method <@mth="Q"><@sub="7"> (the default in R) or <@mth="Q"><@sub="8"> (the one recommended by Hyndman and Fan) can be selected instead via the <@xrf="set"> command, as in 

<code>          
     set quantile_type Q7 # or Q8
</code>

For example, the code 

<code>          
     set verbose off
     matrix x = seq(1,7)'
     set quantile_type Q6
     printf "Q6: %g\n", quantile(x, 0.45)
     set quantile_type Q7
     printf "Q7: %g\n", quantile(x, 0.45)
     set quantile_type Q8
     printf "Q8: %g\n", quantile(x, 0.45)
</code>

produces the following output: 

<code>          
     Q6: 3.6
     Q7: 3.7
     Q8: 3.63333
</code>

# randgen probdist
Output: 	series 
Arguments:	<@var="d">  (string)
		<@var="p1">  (scalar or series)
		<@var="p2">  (scalar or series, conditional)
		<@var="p3">  (scalar, conditional)
Examples: 	<@lit="series x = randgen(u, 0, 100)">
		<@lit="series t14 = randgen(t, 14)">
		<@lit="series y = randgen(B, 0.6, 30)">
		<@lit="series g = randgen(G, 1, 1)">
		<@lit="series P = randgen(P, mu)">

All-purpose random number generator. The argument <@var="d"> is a string (in most cases just a single character) which specifies the distribution from which the pseudo-random numbers should be drawn. The arguments <@var="p1"> to <@var="p3"> specify the parameters of the selected distribution; the number of such parameters depends on the distribution. For distributions other than the beta-binomial, the parameters <@var="p1"> and (if applicable) <@var="p2"> may be given as either scalars or series: if they are given as scalars the output series is identically distributed, while if a series is given for <@var="p1"> or <@var="p2"> the distribution is conditional on the parameter value at each observation. In the case of the beta-binomial all the parameters must be scalars. 

Specifics are given below: the string code for each distribution is shown in parentheses, followed by the interpretation of the argument <@var="p1"> and, where applicable, <@var="p2"> and <@var="p3">. 

<indent>
• Uniform (continuous) (u or U): minimum, maximum 
</indent>

<indent>
• Uniform (discrete) (i): minimum, maximum 
</indent>

<indent>
• Normal (z, n, or N): mean, standard deviation 
</indent>

<indent>
• Student's t (t): degrees of freedom 
</indent>

<indent>
• Chi square (c, x, or X): degrees of freedom 
</indent>

<indent>
• Snedecor's F (f or F): df (num.), df (den.) 
</indent>

<indent>
• Gamma (g or G): shape, scale 
</indent>

<indent>
• Binomial (b or B): probability, number of trials 
</indent>

<indent>
• Poisson (p or P): mean 
</indent>

<indent>
• Exponential (exp): scale 
</indent>

<indent>
• Logistic (lgt or s): location, scale 
</indent>

<indent>
• Weibull (w or W): shape, scale 
</indent>

<indent>
• Laplace (l or L): mean, scale 
</indent>

<indent>
• Generalized Error (E): shape 
</indent>

<indent>
• Beta (beta): shape1, shape2 
</indent>

<indent>
• Beta-Binomial (bb): trials, shape1, shape2 
</indent>

See also <@ref="normal">, <@ref="uniform">, <@ref="mrandgen">, <@ref="randgen1">. 

# randgen1 probdist
Output: 	scalar 
Arguments:	<@var="d">  (character)
		<@var="p1">  (scalar)
		<@var="p2">  (scalar, conditional)
Examples: 	<@lit="scalar x = randgen1(z, 0, 1)">
		<@lit="scalar g = randgen1(g, 3, 2.5)">

Works like <@ref="randgen"> except that the return value is a scalar rather than a series. 

The first example above calls for a value from the standard normal distribution, while the second specifies a drawing from the Gamma distribution with shape 3 and scale 2.5. 

See also <@ref="mrandgen">. 

# randint probdist
Output: 	integer 
Arguments:	<@var="min">  (integer)
		<@var="max">  (integer)

Returns a pseudo-random integer in the closed interval [<@var="min">, <@var="max">]. See also <@ref="randgen">. 

# randperm probdist
Output: 	vector 
Arguments:	<@var="n">  (integer)
		<@var="k">  (integer, optional)

If only the first argument is given, returns a row vector containing a random permutation of the integers from 1 to <@var="n">, without repetition of elements. If the second argument is given it must be a positive integer in the range 1 to <@var="n">; in this case the function returns a row vector containing <@var="k"> integers selected randomly from 1 to <@var="n"> without replacement. 

If you wish to sample <@mth="k"> rows from a matrix <@lit="X"> with <@mth="n"> rows (without replacement), that can be accomplished as shown below: 

<code>          
     matrix S = X[randperm(n, k),]
</code>

And if you wish to preserve the original order of the rows in the sample: 

<code>          
     matrix S = X[sort(randperm(n, k)),]
</code>

See also <@ref="resample"> for resampling with replacement. 

# rank linalg
Output: 	integer 
Arguments:	<@var="X">  (matrix)
		<@var="tol">  (scalar, optional)

Returns the rank of the <@itl="r">×<@itl="c"> matrix <@var="X">, numerically computed via the singular value decomposition. 

The result of this operation is the number of singular values of <@var="X"> that are found to be numerically greater than 0. The <@var="tol"> optional parameter can be used for tweaking this aspect. Singular values are considered to be non-zero if they are greater than <@mth="m × tol × s">, where <@mth="m"> is the greater of <@mth="r"> and <@mth="c"> and <@mth="s"> is the largest singular value. If the second argument is omitted <@var="tol"> is set to machine epsilon (see <@ref="$macheps">). In some cases, you may want to set <@var="tol"> to a larger value (eg 1.0e-9) in order to avoid overestimating the rank of <@var="X">, which may lead to numerically unstable results. 

See also <@ref="svd">. 

# ranking stats
Output: 	same type as input 
Argument: 	<@var="y">  (series or vector)

Returns a series or vector with the ranks of <@mth="y">. The rank for observation <@mth="i"> is the number of elements that are less than <@mth="y"><@sub="i"> plus one half the number of elements that are equal to <@mth="y"><@sub="i">. (Intuitively, you may think of chess points, where victory gives you one point and a draw gives you half a point.) One is added so the lowest rank is 1 instead of 0. 

See also <@ref="sort">, <@ref="sortby">. 

# rcond linalg
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the reciprocal condition number for <@var="A"> with respect to the 1-norm. In many circumstances, this is a better measure of the sensitivity of <@var="A"> to numerical operations such as inversion than the determinant. 

The value is computed as the reciprocal of the product, 1-norm of <@var="A"> times 1-norm of <@var="A">-inverse. 

See also <@ref="det">, <@ref="ldet">, <@ref="onenorm">. 

# Re complex
Output: 	matrix 
Argument: 	<@var="C">  (complex matrix)

Returns a real matrix of the same dimensions as <@var="C">, holding the real part of the input matrix. See also <@ref="Im">. 

# readfile strings
Output: 	string 
Arguments:	<@var="fname">  (string)
		<@var="codeset">  (string, optional)

If a file by the name of <@var="fname"> exists and is readable, returns a string containing the content of this file, otherwise flags an error. If <@var="fname"> does not contain a full path specification, it will be looked for in several “likely” locations, beginning with the currently set <@xrf="workdir">. If the file in question is gzip-compressed, this is handled transparently. 

If <@var="fname"> starts with the identifier of a supported internet protocol (<@lit="http://">, <@lit="ftp://"> or <@lit="https://">), libcurl is invoked to download the resource. See also <@ref="curl"> for more elaborate downloading operations. 

If the text to be read is not encoded in UTF-8, gretl will try recoding it from the current locale codeset if that is not UTF-8, or from ISO-8859-15 otherwise. If this simple default does not meet your needs you can use the optional second argument to specify a codeset. For example, if you want to read text in Microsoft codepage 1251 and that is not your locale codeset, you should give a second argument of <@lit=""cp1251"">. 

Examples: 

<code>          
        string web_page = readfile("http://gretl.sourceforge.net/")
        print web_page

        string current_settings = readfile("@dotdir/.gretl2rc")
        print current_settings
</code>

Also see the <@ref="sscanf"> and <@ref="getline"> functions. 

# regsub strings
Output: 	string 
Arguments:	<@var="s">  (string)
		<@var="match">  (string)
		<@var="repl">  (string)

Returns a copy of <@var="s"> in which all occurrences of the pattern <@var="match"> are replaced using <@var="repl">. The arguments <@var="match"> and <@var="repl"> are interpreted as Perl-style regular expressions. 

See also <@ref="strsub"> for simple substitution of literal strings. 

# remove data-utils
Output: 	integer 
Argument: 	<@var="fname">  (string)

If a file by the name of <@var="fname"> exists and is writable by the user, this function removes (deletes) the file and returns 0. If there is no such file or for some reason the file cannot be deleted, a non-zero error code is returned. 

If <@var="fname"> does not specify a full path, it is taken to be relative to the current <@xrf="workdir">. 

# replace data-utils
Output: 	same type as input 
Arguments:	<@var="x">  (series or matrix)
		<@var="find">  (scalar or vector)
		<@var="subst">  (scalar or vector)

Replaces each element of <@var="x"> equal to the <@mth="i">-th element of <@var="find"> with the corresponding element of <@var="subst">. 

If <@var="find"> is a scalar, <@var="subst"> must also be a scalar. If <@var="find"> and <@var="subst"> are both vectors, they must have the same number of elements. But if <@var="find"> is a vector and <@var="subst"> a scalar, then all matches will be replaced by <@var="subst">. 

Example: 

<code>          
     a = {1,2,3;3,4,5}
     find = {1,3,4}
     subst = {-1,-8, 0}
     b = replace(a, find, subst)
     print a b
</code>

produces 

<code>          
          a (2 x 3)

          1   2   3
          3   4   5

          b (2 x 3)

          -1    2   -8
          -8    0    5
</code>

# resample stats
Output: 	same type as input 
Arguments:	<@var="x">  (series or matrix)
		<@var="blocksize">  (integer, optional)
		<@var="draws">  (integer, optional)

The initial description of this function pertains to cross-sectional or time-series data; see below for the case of panel data. 

Resamples from <@var="x"> with replacement. In the case of a series argument, each value of the returned series, <@mth="y"><@sub="t">, is drawn from among all the values of <@mth="x"><@sub="t"> with equal probability. When a matrix argument is given, each row of the returned matrix is drawn from the rows of <@var="x"> with equal probability. See also <@ref="randperm"> for sampling rows from a matrix without replacement. 

The optional argument <@var="blocksize"> represents the block size for resampling by moving blocks. If this argument is given it should be a positive integer greater than or equal to 2. The effect is that the output is composed by random selection with replacement from among all the possible contiguous sequences of length <@var="blocksize"> in the input. (In the case of matrix input, this means contiguous rows.) If the length of the data is not an integer multiple of the block size, the last selected block is truncated to fit. 

<@itl="Number of draws"> 

By default the number of resampled observations in the output is equal to that in the input—if <@var="x"> is a series, the length of the current sample range; if <@var="x"> is a matrix, its number of rows. In the matrix case <@itl="only"> this can be adjusted via the optional third argument, which must be a positive integer. Note that if <@var="blocksize"> is greater than 1, <@var="draws"> refers to the number of individual observations, not the number of blocks. 

<@itl="Panel data"> 

If the argument <@var="x"> is a series and the dataset takes the form of a panel, resampling by moving blocks is not supported. The basic form of resampling is supported, but has this specific interpretation: the data are resampled “by individual”. Suppose you have a panel in which 100 individuals are observed over 5 periods. Then the returned series will again be composed of 100 blocks of 5 observations: each block will be drawn with equal probability from the 100 individual time series, with the time-series order preserved. 

# round math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Rounds to the nearest integer. Note that when <@mth="x"> lies halfway between two integers, rounding is done "away from zero", so for example 2.5 rounds to 3, but <@lit="round(-3.5)"> gives –4. This is a common convention in spreadsheet programs, but other software may yield different results. See also <@ref="ceil">, <@ref="floor">, <@ref="int">. 

# rnameget strings
Output: 	string or array of strings 
Arguments:	<@var="M">  (matrix)
		<@var="r">  (integer, optional)

If the <@var="r"> argument is given, retrieves the name for row <@var="r"> of matrix <@var="M">. If <@var="M"> has no row names attached the value returned is an empty string; if <@var="r"> is out of bounds for the given matrix an error is flagged. 

If no second argument is given, retrieves an array of strings holding the row names from <@var="M">, or an empty array if the matrix does not have row names attached. 

Example: 

<code>          
     matrix A = { 11, 23, 13 ; 54, 15, 46 }
     rnameset(A, "First Second")
     string name = rnameget(A, 2)
     print name
</code>

See also <@ref="rnameset">. 

# rnameset matrix
Output: 	integer 
Arguments:	<@var="M">  (matrix)
		<@var="S">  (array of strings or list)

Attaches names to the rows of the <@itl="m">×<@itl="n"> matrix <@var="M">. If <@var="S"> is a named list, the names are taken from the names of the listed series; the list must have <@mth="m"> members. If <@var="S"> is an array of strings, it should contain <@mth="m"> elements. A single string is also acceptable as the second argument; in that case it should contain <@mth="m"> space-separated substrings. 

The nominal return value is 0 on successful completion; in case of failure an error is flagged. See also <@ref="cnameset">. 

Example: 

<code>          
     matrix M = {1, 2; 2, 1; 4, 1}
     strings S = array(3)
     S[1] = "Row1"
     S[2] = "Row2"
     S[3] = "Row3"
     rnameset(M, S)
     print M
</code>

# rows matrix
Output: 	integer 
Argument: 	<@var="X">  (matrix)

Returns the number of rows of the matrix <@var="X">. See also <@ref="cols">, <@ref="mshape">, <@ref="unvech">, <@ref="vec">, <@ref="vech">. 

# schur complex
Output: 	complex matrix 
Arguments:	<@var="A">  (complex matrix)
		<@var="&Z">  (reference to matrix, or <@lit="null">)
		<@var="&w">  (reference to matrix, or <@lit="null">)

Performs the Schur decomposition of the complex matrix <@var="A">, returning a complex upper triangular matrix <@mth="T">. If the second argument is given and is not <@lit="null"> it retrieves a complex matrix <@mth="Z"> holding the Schur vectors associated with <@mth="A"> and <@mth="T">, such that <@mth="A"> = <@mth="ZTZ"><@sup="H">. If the third argument is given it retrieves the eigenvalues of <@mth="A"> in a complex column vector. 

# sd stats
Output: 	scalar or series 
Arguments:	<@var="x">  (series or list)
		<@var="partial">  (boolean, optional)

If <@var="x"> is a series, returns the (scalar) sample standard deviation, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the sample standard deviation of the values of the variables in the list at observation <@mth="t">. By default the standard deviation is recorded as <@lit="NA"> if there are any missing values at <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used to form the statistic. 

See also <@ref="var">. 

# sdc stats
Output: 	row vector 
Arguments:	<@var="X">  (matrix)
		<@var="df">  (scalar, optional)

Returns the standard deviations of the columns of <@var="X">. If <@var="df"> is positive it is used as the divisor for the column variances, otherwise the divisor is the number of rows in <@var="X"> (that is, no degrees of freedom correction is applied). See also <@ref="meanc">, <@ref="sumc">. 

# sdiff transforms
Output: 	same type as input 
Argument: 	<@var="y">  (series or list)

Computes seasonal differences: <@mth="y(t) - y(t-k)">, where <@mth="k"> is the periodicity of the current dataset (see <@ref="$pd"> or <@ref="$panelpd">). Starting values are set to <@lit="NA">. 

When a list is returned, the individual variables are automatically named according to the template <@lit="sd_"><@var="varname"> where <@var="varname"> is the name of the original series. The name is truncated if necessary, and may be adjusted in case of non-uniqueness in the set of names thus constructed. 

See also <@ref="diff">, <@ref="ldiff">. 

# seasonals data-utils
Output: 	list 
Arguments:	<@var="baseline">  (integer, optional)
		<@var="center">  (boolean, optional)

Applicable only if the dataset has a time-series structure with periodicity greater than 1. Returns a list of dummy variables coding for the period or season, named <@lit="S1">, <@lit="S2"> and so on. 

The optional <@var="baseline"> argument can be used to exclude one period from the set of dummies. For example, if you give a baseline value of 1 with quarterly data the returned list will hold dummies for quarters 2, 3 and 4 only. If this argument is omitted or set to zero a full set of dummies is generated; if non-zero, it must be an integer from 1 to the periodicity of the data. 

The <@var="center"> argument, if non-zero, calls for the dummies to be centered; that is, to have their population mean subtracted. For example, with quarterly data centered seasonals will have values –0.25 and 0.75 rather than 0 and 1. 

With weekly data the precise effect depends on whether the data are dated or not. If they are dated, up to 53 seasonals are created, based on the ISO 8601 week number (see <@ref="isoweek">); if not, the maximum number of series is 52 (and over a long time span the “seasonals” will drift out of phase with the calendar year). In the dated weekly case, if you wish to create monthly seasonals this can be done as follows: 

<code>          
     series month = $obsminor
     list months = dummify(month)
</code>

See <@ref="dummify"> for details. 

# selifc matrix
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="b">  (row vector)

Selects from <@var="A"> only the columns for which the corresponding element of <@var="b"> is non-zero. <@var="b"> must be a row vector with the same number of columns as <@var="A">. 

See also <@ref="selifr">. 

# selifr matrix
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="b">  (column vector)

Selects from <@var="A"> only the rows for which the corresponding element of <@var="b"> is non-zero. <@var="b"> must be a column vector with the same number of rows as <@var="A">. 

See also <@ref="selifc">, <@ref="trimr">. 

# seq matrix
Output: 	row vector 
Arguments:	<@var="a">  (scalar)
		<@var="b">  (scalar)
		<@var="k">  (scalar, optional)

Given only two arguments, returns a row vector filled with values from <@var="a"> to <@var="b"> with an increment of 1, or a decrement of 1 if <@var="a"> is greater than <@var="b">. 

If the third argument is given, returns a row vector containing a sequence of values starting with <@var="a"> and incremented (or decremented, if <@var="a"> is greater than <@var="b">) by <@var="k"> at each step. The final value is the largest member of the sequence that is less than or equal to <@var="b"> (or mutatis mutandis for <@var="a"> greater than <@var="b">). The argument <@var="k"> must be positive. 

See also <@ref="ones">, <@ref="zeros">. 

# setnote data-utils
Output: 	integer 
Arguments:	<@var="b">  (bundle)
		<@var="key">  (string)
		<@var="note">  (string)

Sets a descriptive note for the object identified by <@var="key"> in the bundle <@var="b">. This note will be shown when the <@lit="print"> command is used on the bundle. This function returns 0 on success or non-zero on failure (for example, if there is no object in <@var="b"> under the given <@var="key">). 

# sgn math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the sign function of <@var="x">; that is, 0 if <@var="x"> is zero, 1 if <@var="x"> is positive, –1 if <@var="x"> is negative, or <@lit="NA"> if <@var="x"> is Not a Number. 

# simann numerical
Output: 	scalar 
Arguments:	<@var="&b">  (reference to matrix)
		<@var="f">  (function call)
		<@var="maxit">  (integer, optional)

Implements simulated annealing, which may be helpful in improving the initialization for a numerical optimization problem. 

On input the first argument holds the initial value of a parameter vector and the second argument specifies a function call which returns the (scalar) value of the maximand. The optional third argument specifies the maximum number of iterations (which defaults to 1024). On successful completion, <@lit="simann"> returns the final value of the maximand and <@var="b"> holds the associated parameter vector. 

For more details and an example see chapter 37 of the <@pdf="Gretl User's Guide#chap:numerical">. See also <@ref="BFGSmax">, <@ref="NRmax">. 

# sin math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the sine of <@var="x">. See also <@ref="cos">, <@ref="tan">, <@ref="atan">. 

# sinh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the hyperbolic sine of <@var="x">. 

See also <@ref="asinh">, <@ref="cosh">, <@ref="tanh">. 

# skewness stats
Output: 	scalar 
Argument: 	<@var="x">  (series)

Returns the skewness value for the series <@var="x">, skipping any missing observations. 

# sleep programming
Output: 	scalar 
Argument: 	<@var="ns">  (scalar)

Not of any direct use for econometrics, but can be useful for testing parallelization methods. This function simply causes the current thread to “sleep”—that is, do nothing—for <@var="ns"> seconds. The argument must be non-negative. On wake-up, the function returns 0. 

# smplspan data-utils
Output: 	scalar 
Arguments:	<@var="startobs">  (string)
		<@var="endobs">  (string)
		<@var="pd">  (integer)

Returns the number of observations from <@var="startobs"> to <@var="endobs"> (inclusive) for time-series data with frequency <@var="pd">. 

The first two arguments should be given in the form preferred by gretl for annual, quarterly or monthly data—for example, <@lit="1970">, <@lit="1970:1"> or <@lit="1970:01"> for each of these frequencies, respectively—or as ISO 8601 dates, <@lit="YYYY-MM-DD">. 

The <@var="pd"> argument must be 1, 4 or 12 (annual, quarterly, monthly); one of the daily frequencies (5, 6, 7); or 52 (weekly). If <@var="pd"> equals 1, 4 or 12, then ISO 8601 dates are acceptable for the first two arguments if they indicate the start of the period in question. For example, <@lit="2015-04-01"> is acceptable in place of <@lit="2015:2"> to represent the second quarter of 2015. 

If you already have a dataset of frequency <@var="pd"> in place, with a sufficient range of observations, then the result of this function could easily be emulated using <@ref="obsnum">. The advantange of <@lit="smplspan"> is that you can calculate the number of observations without having a suitable dataset (or any dataset) in place. An example follows: 

<code>          
     scalar T = smplspan("2010-01-01", "2015-12-31", 5)
     nulldata T
     setobs 5 2010-01-01
</code>

This produces: 

<code>          
     ? scalar T = smplspan("2010-01-01", "2015-12-31", 5)
     Generated scalar T = 1565
     ? nulldata T
     periodicity: 1, maxobs: 1565
     observations range: 1 to 1565
     ? setobs 5 2010-01-01
     Full data range: 2010-01-01 - 2015-12-31 (n = 1565)
</code>

After the above, you can be confident that the last observation in the dataset created via <@xrf="nulldata"> will be <@lit="2015-12-31">. Note that the number 1565 would have been rather tricky to compute otherwise. 

# sort matrix
Output: 	same type as input 
Argument: 	<@var="x">  (series, vector or strings array)

Sorts <@var="x"> in ascending order. Observations with missing values are skipped if <@mth="x"> is a series, but sorted to the end if <@mth="x"> is a vector. See also <@ref="dsort">, <@ref="values">. For matrices specifically, see <@ref="msortby">. 

# sortby stats
Output: 	series 
Arguments:	<@var="y1">  (series)
		<@var="y2">  (series)

Returns a series containing the elements of <@var="y2"> sorted by increasing value of the first argument, <@var="y1">. See also <@ref="sort">, <@ref="ranking">. 

# sphericorr stats
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="mode">  (integer)
		<@var="&J">  (reference to matrix, or <@lit="null">)

Calculates the spherical coordinates representation of a correlation matrix, or its inverse, depending on the value of the <@var="mode"> parameter. 

When <@var="mode"> is 0 or omitted, <@var="X"> is assumed to be an <@itl="n">×<@itl="n"> correlation matrix. The returned value will be a vector with <@mth="n(n-1)/2"> elements between 0 and π. In this mode the reference to <@var="J"> is ignored. 

When <@var="mode"> is 1 or 2 the inverse transformation is performed, so <@var="X"> must be a vector with <@mth="n(n-1)/2"> elements between 0 and π. The return value is the correlation matrix <@mth="R"> if <@var="mode"> equals 1, or its Cholesky factor <@mth="K"> if <@var="mode"> equals 2. The optional pointer to matrix <@var="J">, if present, retrieves the Jacobian of vech(<@mth="R">) or vech(<@mth="K">) with respect to <@mth="X">. 

Note that the spherical coordinates representation makes it very easy to compute the log-determinant of the correlation matrix <@mth="R">: 

<code>          
    omega = sphericorr(X)
    log_det = 2 * sum(log(sin(omega)))
</code>

# sprintf strings
Output: 	string 
Arguments:	<@var="format">  (string)
		... (see below)

The returned string is constructed by printing the values of the trailing arguments, indicated by the dots above, under the control of <@var="format">. It is meant to give you great flexibility in creating strings. The <@var="format"> is used to specify the precise way in which you want the arguments to be printed. 

In general, <@var="format"> must be an expression that evaluates to a string, but in most cases will just be a string literal (an alphanumeric sequence surrounded by double quotes). Some character sequences in the format have a special meaning: those beginning with the percent character (%) are interpreted as “placeholders” for the items contained in the argument list; moreover, special characters such as the newline character are represented via a combination beginning with a backslash. 

For example, the code below 

<code>          
     scalar x = sqrt(5)
     string claim = sprintf("sqrt(%d) is (roughly) %6.4f.\n", 5, x)
     print claim
</code>

will output 

<code>          
     sqrt(5) is (roughly) 2.2361.
</code>

The expression <@lit="%d"> in the format string indicates that we want an integer at that place in the output; since it is the leftmost “percent” expression, it is matched to the first argument, that is 5. The second special sequence is <@lit="%6.4f">, which stands for a decimal value at least 6 digits wide with 4 digits after the decimal separator. The number of such sequences must match the number of arguments following the format string. 

See the help page for the <@xrf="printf"> command for more details about the syntax you can use in format strings. 

# sqrt math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the positive square root of <@var="x">; produces <@lit="NA"> for negative values. 

Note that if the argument is a matrix the operation is performed element by element. For the “matrix square root” see <@ref="cholesky">. 

# square transforms
Output: 	list 
Arguments:	<@var="L">  (list)
		<@var="cross-products">  (boolean, optional)

Returns a list that references the squares of the variables in the list <@var="L">, named on the pattern <@lit="sq_"><@var="varname">. If the optional second argument is present and has a non-zero value, the returned list also includes the cross-products of the elements of <@var="L">; these are named on the pattern <@var="var1"><@lit="_"><@var="var2">. In these patterns the input variable names are truncated if need be, and the output names may be adjusted in case of duplication of names in the returned list. 

# sscanf strings
Output: 	integer 
Arguments:	<@var="src">  (string or array of strings)
		<@var="format">  (string)
		... (see below)

Reads values from <@var="src"> under the control of <@var="format"> and assigns these values to one or more trailing arguments, indicated by the dots above. Returns the number of values assigned. This is a simplified version of the <@lit="sscanf"> function in the C programming language, with an extension to the scanning of an entire matrix; this extension is described under the leading “Scanning a matrix” below. Note that giving an array of strings as <@var="src"> is acceptable only in the case of matrix scanning. 

<@var="src"> may be either a literal string, enclosed in double quotes, or the name of a predefined string variable. <@var="format"> is defined similarly to the format string in <@xrf="printf"> (more on this below). <@var="args"> should be a comma-separated list containing the names of predefined variables: these are the targets of conversion from <@var="src">. (For those used to C: one can prefix the names of numerical variables with <@lit="&"> but this is not required.) 

Literal text in <@var="format"> is matched against <@var="src">. Conversion specifiers start with <@lit="%">, and recognized conversions include <@lit="%f">, <@lit="%g"> or <@lit="%lf"> for floating-point numbers; <@lit="%d"> for integers; <@lit="%s"> for strings. You may insert a positive integer after the percent sign: this sets the maximum number of characters to read for the given conversion. Alternatively, you can insert a literal <@lit="*"> after the percent to suppress the conversion (thereby skipping any characters that would otherwise have been converted for the given type). For example, <@lit="%3d"> converts the next 3 characters in <@var="src"> to an integer, if possible; <@lit="%*g"> skips as many characters in <@var="src"> as could be converted to a single floating-point number. 

In addition to <@lit="%s"> conversion for strings, a simplified version of the C format <@lit="%"><@var="N"><@lit="["><@var="chars"><@lit="]"> is available. In this format <@var="N"> is the maximum number of characters to read and <@var="chars"> is a set of acceptable characters, enclosed in square brackets: reading stops if <@var="N"> is reached or if a character not in <@var="chars"> is encountered. The function of <@var="chars"> can be reversed by giving a circumflex, <@lit="^">, as the first character; in that case reading stops if a character in the given set is found. (Unlike C, the hyphen does not play a special role in the <@var="chars"> set.) 

If the source string does not (fully) match the format, the number of conversions may fall short of the number of arguments given. This is not in itself an error so far as gretl is concerned. However, you may wish to check the number of conversions performed; this is given by the return value. Some simple examples follow: 

<code>          
     # scanning scalar values
     scalar x
     scalar y
     sscanf("123456", "%3d%3d", x, y)
     # scanning string values
     string s = "one two"
     string s1
     string s2
     sscanf(s, "%s %s", s1, s2)
     print s1 s2
</code>

<@itl="Scanning a matrix"> 

Matrix scanning must be signaled by the special conversion specification “<@lit="%m">”. The maximum number of rows to be read can be specified by inserting an integer between the “<@lit="%">” sign and the “<@lit="m">” for matrix. Two variants are supported: <@var="src"> a single string representing a matrix, and <@var="src"> an array of strings. We describe these options in turn. 

If <@var="src"> is a single string argument the scanner reads a line of input and counts the (space- or tab-separated) number of numeric fields. This defines the number of columns in the matrix. By default, reading then proceeds for as many lines (rows) as contain the same number of numeric columns, but the maximum number of rows can be limited via the optional integer value mentioned above. 

If <@var="src"> is an array of strings the output is necessarily a column vector, each element of which is the numerical conversion of the corresponding string, or <@lit="NA"> if the string is not numeric. Here are some simple examples. 

<code>          
     # scanning a single string
     string s = sprintf("1 2 3 4\n5 6 7 8")
     print s
     matrix m
     sscanf(s, "%m", m)
     print m
     # scanning an array of strings
     strings S = defarray("1.1", "2.2", "3.3", "4.4", "5.5")
     sscanf(S, "%4m", m)
     print m
</code>

# sst stats
Output: 	scalar 
Argument: 	<@var="y">  (series)

Returns the sum of squared deviations from the mean for the non-missing observations in series <@var="y">. See also <@ref="var">. 

# stack panel
Output: 	series 
Arguments:	<@var="L">  (list)
		<@var="n">  (integer)
		<@var="offset">  (integer, optional)

Designed for manipulation of data into the stacked time series format required by gretl for panel data. The return value is a series obtained by stacking “vertically” <@var="n"> observations from each series in the list <@var="L">. By default the first <@var="n"> observations are used (corresponding to <@var="offset"> = 0) but the starting point can be shifted by supplying a positive value for <@var="offset">. If the resulting series is longer than the existing dataset, observations are added as needed. 

This function can handle the case where a data file holds side-by-side time series for a number of cross-sectional units, as well as the case where time runs horizontally and each row represents a cross-sectional unit. 

See the section titled “Panel data specifics” in chapter 4 of the <@pdf="Gretl User's Guide#chap:datafiles"> for details and examples of usage. 

# stdize transforms
Output: 	same type as input 
Arguments:	<@var="X">  (series, list or matrix)
		<@var="v">  (integer, optional)

By default, returns a standardized version of the series, list or matrix: the input is centered and divided by its sample standard deviation (with a degrees of freedom correction of 1). Results are computed by column in the case of matrix input. 

The optional second argument can be used to inflect the result. A non-negative value of <@var="v"> sets the degrees of freedom correction used in the standard deviation, so <@var="v"> = 0 gives the maximum likelihood estimator. As a special case, if <@var="v"> equals –1 only centering is performed. 

# strftime calendar
Output: 	string 
Arguments:	<@var="tm">  (scalar)
		<@var="format">  (string, optional)

The argument <@var="tm"> is taken to give the number of seconds since the start of the year 1970 according to UTC (Coordinated Universal Time, once known as Greenwich Mean Time), and the return value is a string giving the corresponding date and/or time—either in a format specified via the second, optional argument or, by default, the “preferred date and time representation for the current locale” as determined by the system C library. 

Warning: this function behaves differently on Windows and Unix-like operating systems for dates prior to January 1, 1970. On unix-like systems (Linux, macOS) negative arguments can be used to represent such dates, so negative values result in regular date strings; on Windows, such dates are not supported and the return value is a null string. 

Values of <@var="tm"> suitable for use with this function may be obtained via the <@ref="$now"> accessor or the <@ref="strptime"> function. 

The formatting options may be found by consulting the <@lit="strftime"> manual page, on systems which have such pages, or via one of the many websites which present relevant information, such as <@url="https://devhints.io/strftime">. 

# stringify strings
Output: 	integer 
Arguments:	<@var="y">  (series)
		<@var="S">  (array of strings)

Provides a means of defining string values for the series <@var="y">. Two conditions must be satisfied for this to work: the target series must have nothing but integer values, none of them less than 1, and the array <@var="S"> must have at least <@mth="n"> elements where <@mth="n"> is the largest value in <@var="y">. In addition each element of <@var="S"> must be valid UTF-8. If any of these conditions is not met, an error is flagged. 

The nominal return value is 0 on successful completion. 

See also <@ref="strvals">. 

An alternative to <@lit="stringify"> that may be useful in some contexts is direct assignment from an array of strings to a series: this creates a series whose values are taken from the array in sequence; the number of elements in the array must equal either the full length of the dataset or the length of the current sample range, and values may be repeated as required. 

# strlen strings
Output: 	integer 
Argument: 	<@var="s">  (string or array of strings)

If <@var="s"> is a single string, returns the number of UTF-8 characters it contains. Note that this does not equal the number of bytes if some characters are outside of the printable-ASCII range; if you want the number of bytes, you can use the <@ref="nelem"> function. For example: 

<code>          
     string s = "¡Olé!"
     printf "strlen(s) = %d, nelem(s) = %d\n", strlen(s), nelem(s)
</code>

should return 

<code>          
     strlen(s) = 5, nelem(s) = 7
</code>

If the argument is an array of strings the return value is a column vector holding the number of characters in each string. A string-valued series is also an acceptable argument: in this case the return value is a series holding the length of the string values over the current sample range. 

# strncmp strings
Output: 	integer 
Arguments:	<@var="s1">  (string)
		<@var="s2">  (string)
		<@var="n">  (integer, optional)

Compares the two string arguments and returns an integer less than, equal to, or greater than zero if <@var="s1"> is found, respectively, to be less than, to match, or be greater than <@var="s2">, up to the first <@var="n"> characters. If <@var="n"> is omitted the comparison proceeds as far as possible. 

Note that if you just want to compare two strings for equality, that can be done without using a function, as in <@lit="if (s1 == s2) ..."> 

# strptime calendar
Output: 	scalar 
Arguments:	<@var="s">  (string)
		<@var="format">  (string)

This function is the converse of <@ref="strftime">; it parses the date/time string <@var="s"> using the specified <@var="format"> and returns a scalar giving the number of seconds since the start of 1970 according to Coordinated Universal Time (UTC). 

Warning: this function behaves differently on Windows and Unix-like operating systems for dates prior to January 1, 1970. On unix-like systems (Linux, macOS) negative offsets in seconds are returned; on Windows, such dates are not supported and the return value is NA. 

The <@var="format"> options may be found by consulting the <@lit="strptime"> manual page, on systems which have such pages, or via one of the many websites which present relevant information, such as <@url="http://man7.org/linux/man-pages/man3/strptime.3.html">. 

The example below shows how one can convert date information from one format to another. 

<code>          
     scalar tm = strptime("Thursday 02/07/19", "%A %m/%d/%y")
     eval strftime(tm) # default output
     eval strftime(tm, "%B %d, %Y")
</code>

In the US English locale the result is 

<code>          
     Thu 07 Feb 2019 12:00:00 AM EST
     February 07, 2019
</code>

# strsplit strings
Output: 	string or array of strings 
Arguments:	<@var="s">  (string)
		<@var="sep">  (string, optional)
		<@var="i">  (integer, optional)

In basic usage, with a single argument, returns the array of strings that results from the splitting of <@var="s"> on white space (that is on any combination of the space, tab and/or newline characters). 

The optional second argument can be used to specify the separator used for splitting <@var="s">. For example 

<code>          
     string basket = "banana,apple,jackfruit,orange"
     strings S = strsplit(basket, ",")
</code>

will split the input into an array of four strings using comma as separator. 

The backslash-escape sequences “<@lit="\n">”, “<@lit="\r">” and “<@lit="\t">” are taken to represent newline, carriage return and tab, respectively, in the optional <@var="sep"> argument. If you wish to include a literal backslash as a separator character you should double it, as in “<@lit="\\">”. Example: 

<code>          
     string s = "c:\fiddle\sticks"
     strings S = strsplit(s, "\\")
</code>

Regardless of the separator, the members of the returned array are trimmed of any leading or trailing white space. Correspondingly, if <@var="sep"> contains non-whitespace characters then it is stripped of any leading or trailing space. 

If an integer value greater than zero is given as the third argument the return value is a single string, namely the (1-based) element <@var="i"> of the array that would otherwise be produced. If <@var="i"> is less than 1 that provokes an error, but if <@var="i"> is greater than the implied number of elements an empty string is returned. 

# strstr strings
Output: 	string 
Arguments:	<@var="s1">  (string)
		<@var="s2">  (string)
		<@var="ign_case">  (boolean, optional)

Searches <@var="s1"> for an occurrence of the string <@var="s2">. If a match is found, returns a copy of the portion of <@var="s1"> that starts with <@var="s2">, otherwise returns an empty string. 

Example: 

<code>          
          string s1 = "Gretl is an econometrics package"
          string s2 = strstr(s1, "an")
          print s2
</code>

If the optional argument <@var="ign_case"> is nonzero, the search is case-insensitive. For example, 

<code>          
     strstr("Chicago", "c")
</code>

returns “cago”, but 

<code>          
     strstr("Chicago", "c", 1)
</code>

returns “Chicago”. 

If you just wish to find out if <@var="s1"> contains <@var="s2"> (boolean test), see <@ref="instring">. 

# strstrip strings
Output: 	string 
Argument: 	<@var="s">  (string)

Returns a copy of the argument <@var="s"> from which leading and trailing white space have been removed. 

Example: 

<code>          
          string s1 = "    A lot of white space.  "
          string s2 = strstrip(s1)
          print s1 s2
</code>

# strsub strings
Output: 	string 
Arguments:	<@var="s">  (string or array of strings)
		<@var="find">  (string)
		<@var="subst">  (string)

Returns a copy of <@var="s"> in which all occurrences of <@var="find"> are replaced by <@var="subst">. See also <@ref="regsub"> for more complex string replacement via regular expressions. 

Example: 

<code>          
          string s1 = "Hello, Gretl!"
          string s2 = strsub(s1, "Gretl", "Hansl")
          print s2
</code>

# strvals strings
Output: 	array of strings 
Arguments:	<@var="y">  (series)
		<@var="subsample">  (boolean, optional)

If the series <@var="y"> is string-valued, returns by default an array containing all its distinct values (irrespective of the current setting of the sample range), ordered by the associated numerical values starting at 1. If the dataset is currently subsampled you can give a non-zero value for the optional second argument to obtain an array holding just the string values present in the subsample. 

If <@var="y"> is not string-valued an empty strings array is returned. See also <@ref="stringify">. 

An alternative to <@lit="strvals"> that may be useful in some contexts is direct assignment of a string-valued series to an array of strings: this provides not just the distinct values, but all values of the series in the current sample range. 

# substr strings
Output: 	string 
Arguments:	<@var="s">  (string)
		<@var="start">  (integer)
		<@var="end">  (integer)

Returns the substring of <@var="s"> from the character with (1-based) index <@var="start"> to that with index <@var="end">, inclusive, or from <@var="start"> to the end of <@var="s"> if <@var="end"> is –1. 

For example, the code below 

<code>          
          string s1 = "Hello, Gretl!"
          string s2 = substr(s1, 8, 12)
          print s2
</code>

gives: 

<code>          
     ? print s2
     Gretl
</code>

It should be noted that in some cases you may be willing to trade clarity for conciseness, and use slicing and increment operators, as in 

<code>          
          string s1 = "Hello, Gretl!"
          string s2 = s1[8:12]
          string s3 = s1 + 7
          print s2
          print s3
</code>

which would give you 

<code>          
     ? print s2
     Gretl
     ? print s3
     Gretl!
</code>

# sum stats
Output: 	scalar or series 
Arguments:	<@var="x">  (series, matrix or list)
		<@var="partial">  (boolean, optional)

If <@var="x"> is a series, returns the (scalar) sum of the non-missing observations in <@var="x">. See also <@ref="sumall">. 

If <@var="x"> is a matrix, returns the sum of the elements of the matrix. 

If <@var="x"> is a list, returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the sum of the values of the variables in the list at observation <@mth="t">. By default the sum is recorded as <@lit="NA"> if there are any missing values at <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used to form the sum. 

# sumall stats
Output: 	scalar 
Argument: 	<@var="x">  (series)

Returns the sum of the observations of <@var="x"> over the current sample range, or <@lit="NA"> if there are any missing values. Use <@ref="sum"> if you want missing values to be skipped. 

# sumc stats
Output: 	row vector 
Argument: 	<@var="X">  (matrix)

Returns the sums of the columns of <@var="X">. See also <@ref="meanc">, <@ref="sumr">. 

# sumr stats
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Returns the sums of the rows of <@var="X">. See also <@ref="meanr">, <@ref="sumc">. 

# svd linalg
Output: 	row vector 
Arguments:	<@var="X">  (matrix)
		<@var="&U">  (reference to matrix, or <@lit="null">)
		<@var="&V">  (reference to matrix, or <@lit="null">)

Performs the singular values decomposition of the matrix <@var="X">. 

The singular values are returned in a row vector. The left and/or right singular vectors <@mth="U"> and <@mth="V"> may be obtained by supplying non-null values for arguments 2 and 3, respectively. For any matrix <@lit="A">, the code 

<code>          
     s = svd(A, &U, &V)
     B = (U .* s) * V
</code>

should yield <@lit="B"> identical to <@lit="A"> (apart from machine precision). 

See also <@ref="eigengen">, <@ref="eigensym">, <@ref="qrdecomp">. 

# svm nonparam
Output: 	series 
Arguments:	<@var="L">  (list)
		<@var="bparms">  (bundle)
		<@var="bmod">  (reference to bundle, optional)
		<@var="bprob">  (reference to bundle, optional)

This function enables the training of, and prediction based on, an SVM (a Support Vector Machine), using LIBSVM as back-end. The list argument <@var="L"> should include the dependent variable followed by the independent variables and the <@var="bparms"> bundle is used to pass options to the SVM mechanism. The return value is a series holding the SVM's predictions. The two optional bundle-pointer argument can be used to retrieve additional information after training and/or prediction. 

For details, please see the PDF documentation for <@mnu="gretlSVM">. 

# tan math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the tangent of <@var="x">. See also <@ref="atan">, <@ref="cos">, <@ref="sin">. 

# tanh math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the hyperbolic tangent of <@var="x">. 

See also <@ref="atanh">, <@ref="cosh">, <@ref="sinh">. 

# tdisagg transforms
Output: 	matrix 
Arguments:	<@var="Y">  (series or matrix)
		<@var="X">  (series, list or matrix, optional)
		<@var="s">  (scalar)
		<@var="opts">  (bundle, optional)
		<@var="results">  (bundle, optional)

Performs temporal disaggregation (conversion to higher frequency) of the time-series data in <@var="Y">. The argument <@var="s"> gives the expansion factor (for example, 3 for quarterly to monthly). The argument <@var="X"> may contain one or more covariates at the higher frequency to aid in the disaggregation. Several options may be passed in <@var="opts">, and details of the disaggregation may be retrieved via <@var=" results">. 

See chapter 9 of the <@pdf="Gretl User's Guide#chap:tdisagg"> for details. 

# toepsolv linalg
Output: 	column vector 
Arguments:	<@var="c">  (vector)
		<@var="r">  (vector)
		<@var="b">  (vector)
		<@var="det">  (reference to scalar, optional)

Solves a Toeplitz system of linear equations, that is <@mth="Tx = b"> where <@mth="T"> is a square matrix whose element <@mth="T"><@sub="i,j"> equals <@mth="c"><@sub="i-j"> for <@mth="i>=j"> and <@mth="r"><@sub="j-i"> for <@mth="i<=j">. Note that the first elements of <@mth="c"> and <@mth="r"> must be equal, otherwise an error is returned. Upon successful completion, the function returns the vector <@mth="x">. 

The algorithm used here takes advantage of the special structure of the matrix <@mth="T">, which makes it much more efficient than other unspecialized algorithms, especially for large problems. Warning: in certain cases, the function may spuriously issue a singularity error when in fact the matrix <@mth="T"> is nonsingular; this problem, however, cannot arise when <@mth="T"> is positive definite. 

If the optional argument <@var="det"> is supplied (in pointer form), it will contain on exit the determinant of <@mth="T">. For example, the code: 

<code>          
     A = unvech({3;2;1;3;2;3})    # Build a 3x3 Toeplitz matrix
     x = ones(3,1)                # and a 3x1 vector
     print A x
     eval A\x                     # solution via generic inversion
     eval det(A)                  # print the determinant
     a = A[1,]
     d = 0
     eval toepsolv(a, a, x, &d)   # use the dedicated function
     print d
</code>

produces 

<code>          
A (3 x 3)

  3   2   1 
  2   3   2 
  1   2   3 

x (3 x 1)

  1 
  1 
  1 

     0.25000 
 -3.3307e-17 
     0.25000 

8
     0.25000 
  2.7756e-17 
     0.25000 


d =  8.0000000
</code>

# tolower strings
Output: 	string 
Argument: 	<@var="s">  (string)

Returns a copy of <@var="s"> in which any upper-case characters are converted to lower case. 

Examples: 

<code>          
        string s1 = "Hello, Gretl!"
        string s2 = tolower(s1)
        print s2

        string s3 = tolower("Hello, Gretl!")
        print s3
</code>

# toupper strings
Output: 	string 
Argument: 	<@var="s">  (string)

Returns a copy of <@var="s"> in which any lower-case characters are converted to upper case. 

Examples: 

<code>          
        string s1 = "Hello, Gretl!"
        string s2 = toupper(s1)
        print s2

        string s3 = toupper("Hello, Gretl!")
        print s3
</code>

# tr linalg
Output: 	scalar 
Argument: 	<@var="A">  (square matrix)

Returns the trace of the square matrix <@var="A">, that is, the sum of its diagonal elements. See also <@ref="diag">. 

# transp linalg
Output: 	matrix 
Argument: 	<@var="X">  (matrix)

Returns the transpose of <@var="X">. Note: this is rarely used; in order to get the transpose of a matrix, in most cases you can just use the prime operator: <@lit="X'">. 

# trigamma math
Output: 	same type as input 
Argument: 	<@var="x">  (scalar, series or matrix)

Returns the trigamma function of <@var="x">, that is the second derivative of the log of the Gamma function. 

See also <@ref="lngamma">, <@ref="digamma">. 

# trimr matrix
Output: 	matrix 
Arguments:	<@var="X">  (matrix)
		<@var="ttop">  (integer)
		<@var="tbot">  (integer)

Returns a matrix that is a copy of <@var="X"> with <@var="ttop"> rows trimmed at the top and <@var="tbot"> rows trimmed at the bottom. The latter two arguments must be non-negative, and must sum to less than the total rows of <@var="X">. 

See also <@ref="selifr">. 

# typeof data-utils
Output: 	integer 
Argument: 	<@var="name">  (string)

Returns a numeric type-code if <@var="name"> is the identifier of a currently defined object: 1 for scalar, 2 for series, 3 for matrix, 4 for string, 5 for bundle, 6 for array and 7 for list. Otherwise returns 0. The function <@ref="typestr"> may be used to get the string corresponding to the return value. 

This function can also be used to retrieve the type of a bundle member or array element. For example: 

<code>          
     matrices M = array(1)
     eval typestr(typeof(M))
     eval typestr(typeof(M[1]))
</code>

The first <@lit="eval"> result is “array” and the second is “matrix”. 

# typestr data-utils
Output: 	string 
Argument: 	<@var="typecode">  (integer)

Returns the name of the gretl data-type corresponding to <@var="typecode">. This may be used in conjunction with the functions <@ref="typeof"> and <@ref="inbundle">. The value returned is one of “scalar”, “series”, “matrix”, “string”, “bundle”, “array”, “list”, or “null”. 

# uniform probdist
Output: 	series 
Arguments:	<@var="a">  (scalar)
		<@var="b">  (scalar)

Generates a series of uniform pseudo-random variates in the interval (<@var="a">, <@var="b">), or, if no arguments are supplied, in the interval (0,1). The algorithm used by default is the SIMD-oriented Fast Mersenne Twister developed by <@bib="Saito and Matsumoto (2008);saito_matsumoto08">. 

See also <@ref="randgen">, <@ref="normal">, <@ref="mnormal">, <@ref="muniform">. 

# uniq stats
Output: 	column vector 
Argument: 	<@var="x">  (series or vector)

Returns a vector containing the distinct non-missing elements of <@var="x">, not sorted but in their order of appearance. See <@ref="values"> for a variant that sorts the elements. 

# unvech matrix
Output: 	square matrix 
Arguments:	<@var="v">  (vector)
		<@var="d">  (scalar, optional)

If the second argument is omitted, returns an <@itl="n">×<@itl="n"> symmetric matrix obtained by rearranging the elements of <@mth="v">. The number of elements in <@mth="v"> must be a triangular integer—i.e., a number <@mth="k"> such that an integer <@mth="n"> exists with the property <@mth="k = n(n+1)/2">. This is the inverse of the function <@ref="vech">. 

If the argument <@var="d"> is given, the function returns an <@itl="(n+1)">×<@itl="(n+1)"> matrix with the extra-diagonal entries filled with the elements of <@mth="v"> as above. All the elements of the diagonal are set to <@var="d"> instead. 

Example: 

<code>          
        v = {1;2;3}
        matrix one = unvech(v)
        matrix two = unvech(v, 99)
        print one two
</code>

returns 

<code>          
      one (2 x 2)

      1   2 
      2   3 

      two (3 x 3)
      
      99     1     2 
       1    99     3 
       2     3    99
</code>

See also <@ref="mshape">, <@ref="vech">. 

# upper matrix
Output: 	square matrix 
Argument: 	<@var="A">  (square matrix)

Returns an <@itl="n">×<@itl="n"> upper triangular matrix: the elements on and above the diagonal are equal to the corresponding elements of <@var="A">; the remaining elements are zero. 

See also <@ref="lower">. 

# urcpval probdist
Output: 	scalar 
Arguments:	<@var="tau">  (scalar)
		<@var="n">  (integer)
		<@var="niv">  (integer)
		<@var="itv">  (integer)

<@mth="P">-values for the test statistic from the Dickey–Fuller unit-root test and the Engle–Granger cointegration test, as per <@bib="James MacKinnon (1996);mackinnon96">. 

The arguments are as follows: <@var="tau"> denotes the test statistic; <@var="n"> is the number of observations (or 0 for an asymptotic result); <@var="niv"> is the number of potentially cointegrated variables when testing for cointegration (or 1 for a univariate unit-root test); and <@var="itv"> is a code for the model specification: 1 for no constant, 2 for constant included, 3 for constant and linear trend, 4 for constant and quadratic trend. 

Note that if the test regression is “augmented” with lags of the dependent variable, then you should give an <@var="n"> value of 0 to get an asymptotic result. 

See also <@ref="pvalue">, <@ref="qlrpval">. 

# values stats
Output: 	column vector 
Argument: 	<@var="x">  (series or vector)

Returns a vector containing the distinct elements of <@var="x"> sorted in ascending order, ignoring any missing values. If you wish to truncate the values to integers before applying this function, use the expression <@lit="values(int(x))">. 

See also <@ref="uniq">, <@ref="dsort">, <@ref="sort">. 

# var stats
Output: 	scalar or series 
Arguments:	<@var="x">  (series or list)
		<@var="partial">  (boolean, optional)

If <@var="x"> is a series, returns the (scalar) sample variance, skipping any missing observations. 

If <@var="x"> is a list, returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the sample variance of the values of the variables in the list at observation <@mth="t">. By default the variance is recorded as <@lit="NA"> if there are any missing values at <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used to form the statistic. 

In each case the sum of squared deviations from the mean is divided by (<@mth="n"> – 1) for <@mth="n"> > 1. Otherwise the variance is given as zero if <@mth="n"> = 1, or as <@lit="NA"> if <@mth="n"> = 0. 

See also <@ref="sd">. 

# varname strings
Output: 	string 
Argument: 	<@var="v">  (integer or list)

If given an integer argument, returns the name of the variable with ID number <@var="v">, or generates an error if there is no such variable. 

If given a list argument, returns a string containing the names of the variables in the list, separated by commas. If the supplied list is empty, so is the returned string. To get an array of strings as return value, use <@ref="varnames"> instead. 

Example: 

<code>          
        open broiler.gdt
        string s = varname(7)
        print s
</code>

# varnames strings
Output: 	array of strings 
Argument: 	<@var="L">  (list)

Returns an array of strings containing the names of the variables in the list <@var="L">. If the supplied list is empty, so is the returned array. 

Example: 

<code>          
        open keane.gdt
        list L = year wage status
        strings S = varnames(L)
        eval S[1]
        eval S[2]
        eval S[3]
</code>

# varnum data-utils
Output: 	integer 
Argument: 	<@var="varname">  (string)

Returns the ID number of the variable called <@var="varname">, or NA is there is no such variable. 

# varsimul timeseries
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="U">  (matrix)
		<@var="y0">  (matrix)

Simulates a <@mth="p">-order <@mth="n">-variable VAR, that is <@mth="y(t) = A1 y(t-1) + ... + Ap y(t-p) + u(t)."> The coefficient matrix <@var="A"> is composed by stacking the <@mth="A"><@sub="i"> matrices horizontally; it is <@itl="n">×<@itl="np">, with one row per equation. This corresponds to the first <@mth="n"> rows of the matrix <@lit="$compan"> provided by the <@lit="var"> and <@lit="vecm"> commands. 

The <@mth="u_t"> vectors are contained (as rows) in <@var="U"> (<@itl="T">×<@itl="n">). Initial values are in <@var="y0"> (<@itl="p">×<@itl="n">). 

If the VAR contains deterministic terms and/or exogenous regressors, these can be handled by folding them into the <@var="U"> matrix: each row of <@var="U"> then becomes <@mth="u(t) = B'x(t) + e(t)."> 

The output matrix has <@mth="T"> + <@mth="p"> rows and <@mth="n"> columns; it holds the initial <@mth="p"> values of the endogenous variables plus <@mth="T"> simulated values. 

See also <@ref="$compan">, <@xrf="var">, <@xrf="vecm">. 

# vec matrix
Output: 	column vector 
Argument: 	<@var="X">  (matrix)

Stacks the columns of <@var="X"> as a column vector. See also <@ref="mshape">, <@ref="unvech">, <@ref="vech">. 

# vech matrix
Output: 	column vector 
Arguments:	<@var="A">  (square matrix)
		<@var="omit-diag">  (boolean, optional)

This function rearranges the the elements of <@var="A"> on and above the diagonal into a column vector, unless the <@var="omit-diag"> is given a non-zero value, in which case only the entries above the diagonal are considered. 

Typically, this function is used on symmetric matrices, in which case it can be undone by the function <@ref="unvech">. If the input matrix is not symmetric and it's the lower triangle that contains the “right” values, <@lit="vech(A')"> will give the desired answer (its elements may have to be re-ordered, however). See also <@ref="vec">. 

# vma timeseries
Output: 	matrix 
Arguments:	<@var="A">  (matrix)
		<@var="K">  (matrix, optional)
		<@var="horizon">  (integer, optional)

This function yields the VMA representation for a VAR system. If <@mth="y(t) = A1 y(t-1) + ... + Ap y(t-p) + u(t)">, where <@mth="u"><@sub="t"> are the one-step-ahead prediction errors, the corresponding VMA representation is <@mth="y(t) = C0 e(t) + C1 e(t-1) + ...">. The relationship between the forecast errors <@mth="u"><@sub="t"> and the structural shocks <@mth="e"><@sub="t"> is given by <@mth="u(t) = K e(t)">. (Note that <@mth="C"><@sub="0"> = <@mth="K">.) 

The coefficient matrix <@var="A"> is composed by stacking the <@mth="A"><@sub="i"> matrices horizontally; it is <@itl="n">×<@itl="np">, with one row per equation. This corresponds to the first <@mth="n"> rows of the matrix <@lit="$compan"> provided by gretl's <@lit="var"> and <@lit="vecm"> commands. The <@var="K"> matrix is optional, and defaults to the identity matrix if omitted. 

The returned matrix will have <@var="horizon"> rows and <@mth="n"><@sup="2"> columns: its <@mth="i">-th row contains <@mth="C"><@sub="i-1"> in vectorized form. The <@var="horizon"> value defaults to 24 if omitted. 

See also <@ref="irf">. 

# weekday calendar
Output: 	same type as input 
Arguments:	<@var="year">  (scalar or series)
		<@var="month">  (scalar or series)
		<@var="day">  (scalar or series)

Returns the day of the week (Sunday = 0, Monday = 1, etc.) for the date(s) specified by the three arguments, or <@lit="NA"> if the date is invalid. Note that all three arguments must be of the same type, either scalars (integers) or series. 

An alternative call is also supported: if a single argument is given, it is taken to be a date (or series of dates) in ISO 8601 “basic” numeric format, <@lit="YYYYMMDD">. So the following two calls produce the same result, namely 2 (Tuesday). 

<code>          
     eval weekday(1990, 5, 1)
     eval weekday(19900501)
</code>

# wmean transforms
Output: 	series 
Arguments:	<@var="Y">  (list)
		<@var="W">  (list)
		<@var="partial">  (boolean, optional)

Returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the weighted mean of the values of the variables in list <@var="Y"> at observation <@mth="t">, the respective weights given by the values of the variables in list <@var="W"> at <@mth="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

By default the result is NA if any values are missing at observation <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used. 

See also <@ref="wsd">, <@ref="wvar">. 

# wsd transforms
Output: 	series 
Arguments:	<@var="Y">  (list)
		<@var="W">  (list)
		<@var="partial">  (boolean, optional)

Returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the weighted sample standard deviation of the values of the variables in list <@var="Y"> at observation <@mth="t">, the respective weights given by the values of the variables in list <@var="W"> at <@mth="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

By default the result is NA if any values are missing at observation <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used. 

See also <@ref="wmean">, <@ref="wvar">. 

# wvar transforms
Output: 	series 
Arguments:	<@var="X">  (list)
		<@var="W">  (list)
		<@var="partial">  (boolean, optional)

Returns a series <@mth="y"> such that <@mth="y"><@sub="t"> is the weighted sample variance of the values of the variables in list <@var="X"> at observation <@mth="t">, the respective weights given by the values of the variables in list <@var="W"> at <@mth="t">. The weights can therefore be time-varying. The lists <@var="Y"> and <@var="W"> must be of the same length and the weights must be non-negative. 

By default the result is NA if any values are missing at observation <@mth="t">, but if you pass a non-zero value for <@var="partial"> any non-missing values will be used. 

See also <@ref="wmean">, <@ref="wsd">. 

# xmax math
Output: 	scalar 
Arguments:	<@var="x">  (scalar)
		<@var="y">  (scalar)

Returns the greater of <@var="x"> and <@var="y">, or <@lit="NA"> if either value is missing. 

See also <@ref="xmin">, <@ref="max">, <@ref="min">. 

# xmin math
Output: 	scalar 
Arguments:	<@var="x">  (scalar)
		<@var="y">  (scalar)

Returns the lesser of <@var="x"> and <@var="y">, or <@lit="NA"> if either value is missing. 

See also <@ref="xmax">, <@ref="max">, <@ref="min">. 

# xmlget data-utils
Output: 	string 
Arguments:	<@var="buf">  (string)
		<@var="path">  (string or array of strings)
		<@var="matches">  (reference to scalar, optional)

The argument <@var="buf"> should be an XML buffer, as may be retrieved from a suitable website via the <@ref="curl"> function (or read from file via <@ref="readfile">), and the <@var="path"> argument should be either a single XPath specification or an array of such. 

This function returns a string representing the data found in the XML buffer at the specified path. If multiple nodes match the path expression the items of data are printed one per line in the returned string. If an array of paths is given as the second argument the returned string takes the form of a comma-separated buffer, with column <@mth="i"> holding the matches from path <@mth="i">. In this case if a string obtained from the XML buffer contains any spaces or commas it is wrapped in double quotes. 

By default an error is flagged if <@var="path"> is not matched in the XML buffer, but this behavior is modified if you pass the third, optional argument: in that case the argument retrieves a count of the matches and an empty string is returned if there are none. Example call: 

<code>          
     ngot = 0
     ret = xmlget(xbuf, "//some/thing", &ngot)
</code>

However, an error is still flagged in case of a malformed query. 

A good introduction to XPath usage and syntax can be found at <@url="https://www.w3schools.com/xml/xml_xpath.asp">. The back-end for <@lit="xmlget"> is provided by the xpath module of libxml2, which supports XPath 1.0 but not XPath 2.0. 

See also <@ref="jsonget">, <@ref="readfile">. 

# zeromiss transforms
Output: 	same type as input 
Argument: 	<@var="x">  (scalar or series)

Converts zeros to <@lit="NA">s. If <@var="x"> is a series, the conversion is done element by element. See also <@ref="missing">, <@ref="misszero">, <@ref="ok">. 

# zeros matrix
Output: 	matrix 
Arguments:	<@var="r">  (integer)
		<@var="c">  (integer, optional)

Outputs a zero matrix with <@mth="r"> rows and <@mth="c"> columns. If omitted, the number of columns defaults to 1 (column vector). See also <@ref="ones">, <@ref="seq">.