/usr/share/gretl/genrgui.hlp is in gretl-common 2016a-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | ## Accessors
# $ahat access
Output: series
Must follow the estimation of a fixed-effect panel data model. Returns a series containing the estimates of the individual fixed effects (per-unit intercepts).
# $aic access
Output: scalar
Returns the Akaike Information Criterion for the last estimated model, if available. See <@pdf="the Gretl User's Guide"> for details of the calculation.
# $bic access
Output: scalar
Returns Schwarz's Bayesian Information Criterion for the last estimated model, if available. See <@pdf="the Gretl User's Guide"> 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 <@pdf="the Gretl User's Guide"> for details; see also <@ref="$diagpval">.
# $dwpval access
Output: scalar
Returns the p-value for the Durbin–Watson statistic for the model last estimated (if available), computed using the Imhof procedure.
Due to the limited precision of computer 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.
# $fcerr 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">.
# $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 <@pdf="the Gretl User's Guide"> 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.
# $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.
# $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.
# $nvars access
Output: integer
Returns the number of variables in the dataset (including the constant).
# $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
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 major or low-frequency component of each observation (for example, the year).
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">.
# $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 time-series length.
# $pi access
Output: scalar
Returns the value of π in double precision.
# $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 (e.g. <@lit="chow">). See <@pdf="the Gretl User's Guide"> 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.
# $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
genr 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.
# $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.
# $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="nproc">: integer, the number of processors available.
</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="osx">, <@lit="windows"> or <@lit="other">.
</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>
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>
# $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 <@pdf="the Gretl User's Guide"> 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">.
# $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"> with no parameters 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 <@pdf="the Gretl User's Guide"> 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.
# $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 and predetermined 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.
# $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. This accessor is not available for a VECM estimated with a restriction imposed on α, the "loadings" matrix.
# $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.
## 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)
In the simplest version, both <@var="x"> and <@var="byvar"> are individual series. In that case this function returns a matrix with three columns: the first holds the distinct values of <@var="byvar">, sorted in ascending order; the second holds the count of observations at which <@var="byvar"> takes on each of these values; and the third holds 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.
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. If <@var="x"> is a list with <@mth="m"> members then the rightmost <@mth="m"> columns hold the values of the specified statistic for each of the <@var="x"> variables, again calculated on the sub-sample indicated in the first column(s).
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
Argument: <@var="s"> (string)
For <@var="s"> the name of a parameter to a user-defined function, returns the name of the corresponding argument, or an empty string if the argument was anonymous.
# 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"> or <@lit="lists">. 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">.
# 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.
# 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 C's <@lit="atof">, 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.
# 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 pre-defined 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 the chapter on numerical methods in <@pdf="the Gretl User's Guide">. See also <@ref="NRmax">, <@ref="fdjac">, <@ref="simann">.
# bkfilt filters
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 following default values are used: <@var="f1"> = 8, <@var="f2"> = 32, <@var="k"> = 8.
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">.
# boxcox filters
Output: series
Arguments: <@var="y"> (series)
<@var="d"> (scalar)
Returns the Box–Cox transformation with parameter <@var="d"> for the positive series <@var="y">.
The transformed series 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 a text file. The string <@var="fname"> must contain the name of the file from which the bundle is to be read. If this name has the suffix "<@lit=".gz">" it is assumed that gzip compression has been applied in writing the file.
The file in question should be an appropriately defined XML file: it should 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 may expect, such files are generated automatically by the companion function <@ref="bwrite">.
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. In this case the <@var="fname"> argument should be a plain filename, 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">.
# bwfilt filters
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 <@pdf="the Gretl User's Guide"> 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 an XML file named <@var="fname">. For a summary description of its format, see <@ref="bread">. If file <@var="fname"> already exists, it will be overwritten. The return value is 0 on successful completion; if an error occurs, such as the file being unwritable, the return value will be non-zero.
If a non-zero value is given for the <@var="export"> argument, the output file will be written into the user's "dot" directory. In this case a plain filename, without any path component, should be given for the second argument.
See also <@ref="bread">, <@ref="mwrite">.
# cdemean stats
Output: matrix
Argument: <@var="X"> (matrix)
Centers the columns of matrix <@var="X"> around their means.
# 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 (c = z, n, or N): no extra arguments
</indent>
<indent>
• Bivariate normal (D): correlation coefficient
</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>
• Weibull (w or W): shape; 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 linalg
Output: matrix
Arguments: <@var="X"> (matrix)
<@var="Y"> (matrix)
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">.
# 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)
Peforms a Cholesky decomposition of the matrix <@var="A">, which is assumed to be symmetric and positive definite. The result is a lower-triangular matrix <@mth="L"> which satisfies <@mth="A = LL'">. The function will fail if <@var="A"> is not symmetric or not positive definite. See also <@ref="psdroot">.
# chowlin transforms
Output: matrix
Arguments: <@var="Y"> (matrix)
<@var="xfac"> (integer)
<@var="X"> (matrix, optional)
Expands the input data, <@var="Y">, to a higher frequency, using the interpolation 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.
The second argument represents the expansion factor: it should be 3 for expansion from quarterly to monthly or 4 for expansion from annual to quarterly, these being the only supported factors. 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 quadratic 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">.
# cmult linalg
Output: matrix
Arguments: <@var="X"> (matrix)
<@var="Y"> (matrix)
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">.
# colname strings
Output: string
Arguments: <@var="M"> (matrix)
<@var="col"> (integer)
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. See also <@ref="colnames">.
Example:
<code>
matrix A = { 11, 23, 13 ; 54, 15, 46 }
colnames(A, "Col_A Col_B Col_C")
string name = colname(A, 3)
print name
</code>
# colnames matbuild
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. For backward caompatibility, a single string may also be given as the second argument; in that case it should contain <@mth="k"> space-separated substrings.
The return value is 0 on successful completion, non-zero on error. See also <@ref="rownames">.
Example:
<code>
matrix M = {1, 2; 2, 1; 4, 1}
strings S = array(2)
S[1] = "Col1"
S[2] = "Col2"
colnames(M, S)
print M
</code>
# cols matshape
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">.
# 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">.
# corrgm stats
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 is <@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">.
# 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>
See also <@ref="cdf">, <@ref="invcdf">, <@ref="pvalue">.
# 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: scalar
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 <@xrf="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) --quiet
printf "%s\n", line
endloop
endif
</code>
See also the <@ref="jsonget"> function for means of processing JSON data received.
# 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">.
# deseas filters
Output: series
Arguments: <@var="x"> (series)
<@var="c"> (character, optional)
Depends on having TRAMO/SEATS or X-12-ARIMA installed. Returns a deseasonalized (seasonally adjusted) version of the input series <@var="x">, which must be a quarterly or monthly time series. To use X-12-ARIMA give <@lit="X"> as the second argument; to use TRAMO give <@lit="T">. If the second argument is omitted then X-12-ARIMA is used.
Note that if the input series has no detectable seasonal component this function will fail. Also note that both TRAMO/SEATS and X-12-ARIMA offer numerous options; <@lit="deseas"> calls them with all options at their default settings. For both programs, the seasonal factors are calculated on the basis of an automatically selected ARIMA model. One difference between the programs which can sometimes make a substantial difference to the results is that by default TRAMO performs a prior adjustment for outliers while X-12-ARIMA does not.
# det linalg
Output: scalar
Argument: <@var="A"> (square matrix)
Returns the determinant of <@var="A">, computed via the LU factorization. See also <@ref="ldet">, <@ref="rcond">.
# diag matbuild
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 matbuild
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.
# 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">.
# dsort matshape
Output: same type as input
Argument: <@var="x"> (series or vector)
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 = 100*(e-m)
</code>
# eigengen linalg
Output: matrix
Arguments: <@var="A"> (square matrix)
<@var="&U"> (reference to matrix, or <@lit="null">)
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.) It will be 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 just as <@ref="eigengen">, but the argument <@var="A"> must be symmetric (in which case the calculations can be reduced). Unlike <@ref="eigengen">, eigenvalues are returned in ascending order.
Note: if you're interested in the eigen-decomposition 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.
# 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 1 AD; 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.
For the inverse function, see <@ref="isodate">.
# errmsg strings
Output: string
Argument: <@var="errno"> (integer)
Retrieves the gretl error message associated with <@var="errno">. See also <@ref="$error">.
# exists data-utils
Output: integer
Argument: <@var="name"> (string)
Returns 1 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.
# exp math
Output: same type as input
Argument: <@var="x"> (scalar, series or matrix)
Returns <@mth="e"><@sup="x">. Note that in case of matrices 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 or vector)
Produces a column vector holding several statistics which may be used for evaluating the series <@var="f"> as a forecast of the series <@var="y"> over the current sample range. Two vectors of the same length may be given in place of two series arguments.
The layout of the returned vector is as follows:
<code>
1 Mean Error (ME)
2 Mean Squared Error (MSE)
3 Mean Absolute Error (MAE)
4 Mean Percentage Error (MPE)
5 Mean Absolute Percentage Error (MAPE)
6 Theil's U
7 Bias proportion, UM
8 Regression proportion, UR
9 Disturbance proportion, UD
</code>
For details on the calculation of these statistics, and the interpretation of the <@mth="U"> values, please see <@pdf="the Gretl User's Guide">.
# fdjac numerical
Output: matrix
Arguments: <@var="b"> (column vector)
<@var="fcall"> (function call)
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. Example:
<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 by using the <@xrf="set"> command and specify the value 0, 1 or 2 for the <@lit="fdjac_quality"> variable.
For more details and examples see the chapter on numerical methods in <@pdf="the Gretl User's Guide">.
See also <@ref="BFGSmax">, <@xrf="set">.
# fft linalg
Output: matrix
Argument: <@var="X"> (matrix)
Discrete real Fourier transform. If the input matrix <@var="X"> has <@mth="n"> columns, the output has 2<@mth="n"> columns, where the real parts are stored in the odd columns and the complex parts in the even ones.
Should it be necessary to compute the Fourier transform on several vectors with the same number of elements, it is numerically 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 real Fourier transform. It is assumed that <@var="X"> contains <@mth="n"> complex column vectors, with the real part in the odd columns and the imaginary part in the even ones, so the total number of columns should be 2<@mth="n">. 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 numerically more efficient to group them into a matrix rather than invoking <@lit="ffti"> for each vector separately. See also <@ref="fft">.
# filter filters
Output: series
Arguments: <@var="x"> (series or matrix)
<@var="a"> (scalar or vector, optional)
<@var="b"> (scalar or vector, optional)
<@var="y0"> (scalar, 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. Pre-sample values of <@var="x"> are always assumed 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
Argument: <@var="y"> (series)
Returns the 1-based index of the first non-missing observation for the series <@var="y">. Note that if some form of subsampling is in effect, the value returned may be smaller than the dollar variable <@ref="$t1">. See also <@ref="lastobs">.
# fixname strings
Output: string
Argument: <@var="rawname"> (string)
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.
# 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 filters
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.
# gammafun math
Output: same type as input
Argument: <@var="x"> (scalar, series or matrix)
Returns the gamma function of <@var="x">.
# genseries data-utils
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>
list Normals = null
loop i=1..n --quiet
Normals += genseries(sprintf("norm%d", i), normal())
endloop
</code>
On completion <@lit="Normals"> will contain the series <@lit="norm1">, <@lit="norm2"> and so on.
# getenv strings
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">.
# getline strings
Output: scalar
Arguments: <@var="source"> (string)
<@var="target"> (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), 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 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)
Returns Gini's inequality index for the series <@var="y">.
# ginv linalg
Output: matrix
Argument: <@var="A"> (matrix)
Returns <@mth="A"><@sup="+">, the Moore–Penrose or generalized inverse of <@var="A">, computed via the singular value decomposition.
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">.
# halton stats
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 contructed 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)
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">.
As far as we know there isn't an established name for this operation in matrix algebra; it is called "horizontal direct product" in the GAUSS programming language.
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>
# hpfilt filters
Output: series
Arguments: <@var="y"> (series)
<@var="lambda"> (scalar, 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). See also <@ref="bkfilt">, <@ref="bwfilt">.
# I matbuild
Output: square matrix
Argument: <@var="n"> (integer)
Returns an identity matrix with <@var="n"> rows and columns.
# 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 mimima 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 and 6 for array. 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.
# 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="ceil">.
# 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 <@pdf="the Gretl User's Guide"> for details.
See also <@ref="ginv">, <@ref="invpd">.
# invcdf probdist
Output: same type as input
Arguments: <@var="d"> (string)
<@var="…"> (see below)
<@var="p"> (scalar, series or matrix)
Inverse cumulative distribution function calculator. Returns <@mth="x"> such that <@mth="P(X ≤ x) = p">, where the distribution of <@mth="X"> is determined by the string <@var="d">. Between the arguments <@var="d"> 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>
• 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>
• 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 stats
Output: matrix
Arguments: <@var="target"> (integer)
<@var="shock"> (integer)
<@var="alpha"> (scalar between 0 and 1, optional)
This function is available only when the last model estimated was a VAR or VECM. It returns a matrix containing the estimated response of the <@var="target"> variable to an impulse of one standard deviation in the <@var="shock"> variable. These variables are identified by their position in the VAR specification: for example, if <@var="target"> and <@var="shock"> are given as 1 and 3 respectively, the returned matrix gives the response of the first variable in the VAR for a shock to the third variable.
If the optional <@var="alpha"> argument is given, the returned matrix has three columns: the point estimate of the responses, followed by the lower and upper limits of a 1 – α confidence interval obtained via bootstrapping. (So <@var="alpha"> = 0.1 corresponds to 90 percent confidence.) If <@var="alpha"> is omitted or set to zero, only the point estimate is provided.
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">.
# 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">.
# 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.
# isnull data-utils
Output: integer
Argument: <@var="name"> (string)
Returns 0 if <@var="name"> is the identifier for a currently defined object, be it a scalar, a series, a matrix, list, string or bundle; otherwise returns 1.
This function is deprecated: the recommended replacment is (the negation of) <@ref="exists">.
# isoconv calendar
Output: scalar
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 return value from this function is 0 on successful completion, non-zero on error.
# 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 1 AD). 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 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">.
# iwishart stats
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)
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.
For an account of JsonPath syntax, see for example <@url="http://goessner.net/articles/JsonPath/">.
# kdensity stats
Output: matrix
Arguments: <@var="x"> (series or vector)
<@var="scale"> (scalar, optional)
<@var="control"> (boolean, optional)
Computes a kernel density estimate for the series or vector <@var="x">. The returned matrix has two columns, the first holding a set of evenly spaced abscissae and the second the estimated density 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 in
<code>
matrix d = kdensity(x)
gnuplot 2 1 --matrix=d --with-lines --suppress-fitted
</code>
# kfilter filters
Output: scalar
Arguments: <@var="&E"> (reference to matrix, or <@lit="null">)
<@var="&V"> (reference to matrix, or <@lit="null">)
<@var="&S"> (reference to matrix, or <@lit="null">)
<@var="&P"> (reference to matrix, or <@lit="null">)
<@var="&G"> (reference to matrix, or <@lit="null">)
Requires that a Kalman filter be set up. Performs a forward, filtering pass and returns 0 on successful completion or 1 if numerical problems are encountered.
The optional matrix arguments can be used to retrieve the following information: <@var="E"> gets the matrix of one-step ahead prediction errors and <@var="V"> gets the variance matrix for these errors; <@var="S"> gets the matrix of estimated values of the state vector and <@var="P"> the variance matrix of these estimates; <@var="G"> gets the Kalman gain. All of these matrices have <@mth="T "> rows, corresponding to <@mth="T "> observations. For the column dimensions and further details see <@pdf="the Gretl User's Guide">.
See also <@xrf="kalman">, <@ref="ksmooth">, <@ref="ksimul">.
# 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.
# ksimul filters
Output: matrix
Arguments: <@var="v"> (matrix)
<@var="w"> (matrix)
<@var="&S"> (reference to matrix, or <@lit="null">)
Requires that a Kalman filter be set up. Performs a simulation and returns a matrix holding simulated values of the observable variables.
The argument <@var="v"> supplies artificial disturbances for the state transition equation and <@var="w"> supplies disturbances for the observation equation, if applicable. The optional argument <@var="S"> may be used to retrieve the simulated state vector. For details see <@pdf="the Gretl User's Guide">.
See also <@xrf="kalman">, <@ref="kfilter">, <@ref="ksmooth">.
# ksmooth filters
Output: matrix
Argument: <@var="&P"> (reference to matrix, or <@lit="null">)
Requires that a Kalman filter be set up. Performs a backward, smoothing pass and returns a matrix holding smoothed estimates of the state vector. The optional argument <@var="P"> may be used to retrieve the MSE of the smoothed state. For details see <@pdf="the Gretl User's Guide">.
See also <@xrf="kalman">, <@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
Arguments: <@var="p"> (integer)
<@var="y"> (series or list)
<@var="bylag"> (boolean, optional)
Generates lags 1 to <@var="p"> of the series <@var="y">, or if <@var="y"> is a list, of all series in the list. If <@var="p"> = 0, the maximum lag defaults to the periodicity of the data; otherwise <@var="p"> must be positive.
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 and the lag order is greater than 1, the default ordering of the terms in the returned list is by variable: all lags of the first series in the input list followed by all lags of the second series, 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, then lag 2 of all the series, and so on.
# lastobs data-utils
Output: integer
Argument: <@var="y"> (series)
Returns the 1-based index of the last non-missing observation for the series <@var="y">. Note that if some form of subsampling is in effect, the value returned may be larger than the dollar variable <@ref="$t2">. 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. See also <@ref="det">, <@ref="rcond">.
# 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 filters
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">.
# 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.
# 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.
# loess stats
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 <@pdf="the Gretl User's Guide"> for details on nonparametric methods.
# logistic math
Output: same type as input
Argument: <@var="x"> (scalar, series or matrix)
Returns the logistic function of the argument <@var="x">, that is, <@mth="e"><@sup="x">/(1 + <@mth="e"><@sup="x">). If <@var="x"> is a matrix, the function is applied element by element.
# lower matbuild
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">.
# lrvar filters
Output: scalar
Arguments: <@var="y"> (series or vector)
<@var="k"> (integer)
Returns the long-run variance of <@var="y">, calculated using a Bartlett kernel with window size <@var="k">. The default window size, namely the integer part of the cube root of the sample size, can be selected by giving a negative value for <@var="k">.
# 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="imaxc">, <@ref="maxc">, <@ref="minr">.
# mcorr stats
Output: matrix
Argument: <@var="X"> (matrix)
Computes a correlation matrix treating each column of <@var="X"> as a variable. See also <@ref="corr">, <@ref="cov">, <@ref="mcov">.
# mcov stats
Output: matrix
Argument: <@var="X"> (matrix)
Computes a covariance matrix treating each column of <@var="X"> as a variable. 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 given by
sum_{j=-p}^p sum_j w_{|j|} (X_t' u_t u_{t-j} X_{t-j})
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.
# mean stats
Output: scalar or series
Argument: <@var="x"> (series or list)
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">, or <@lit="NA"> if there are any missing values at <@mth="t">.
# meanc stats
Output: row vector
Argument: <@var="X"> (matrix)
Returns the means of the columns of <@var="X">. See also <@ref="meanr">, <@ref="sumc">, <@ref="sdc">.
# 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
Argument: <@var="y"> (series)
The median of the non-missing observations in series <@var="y">. See also <@ref="quantile">.
# mexp linalg
Output: square matrix
Argument: <@var="A"> (square matrix)
Computes the matrix exponential of <@var="A">, using algorithm 11.3.1 from <@bib="Golub and Van Loan (1996);golub96">.
# 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.
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. See also <@ref="missing">, <@ref="ok">, <@ref="zeromiss">.
# mlag stats
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 above operation is carried out for each element in <@var="p">, joining the resulting matrices horizontally.
# mnormal matbuild
Output: matrix
Arguments: <@var="r"> (integer)
<@var="c"> (integer)
Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with standard normal pseudo-random variates. 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: integer
Arguments: <@var="month"> (integer)
<@var="year"> (integer)
<@var="weeklen"> (integer)
Returns the number of (relevant) days in the specified month in the specified year; <@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).
# movavg filters
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.
# 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 probdist
Output: matrix
Arguments: <@var="d"> (string)
<@var="p1"> (scalar)
<@var="p2"> (scalar, 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.
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 matbuild
Output: matrix
Arguments: <@var="fname"> (string)
<@var="import"> (boolean, optional)
Reads a matrix from a file named <@var="fname">. If the filename has the suffix "<@lit=".gz">" it is assumed that gzip compression has been applied in writing the data; if it has the suffix "<@lit=".bin">" the file is assumed to be in binary format (see <@ref="mwrite"> for details). Otherwise the file is assumed to be plain text, conforming to the following specification:
<indent>
• It may start with any number of comments, defined as lines that start with the hash mark, <@lit="#">; such lines are ignored.
</indent>
<indent>
• The first non-comment line must contain two integers, separated by a space or a tab, indicating the number of rows and columns, respectively.
</indent>
<indent>
• The columns must be separated by spaces or tab characters.
</indent>
<indent>
• The decimal separator must be the dot character, "<@lit=".">".
</indent>
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.
Should an error occur (such as the file being badly formatted or inaccessible), an empty matrix is returned.
See also <@ref="bread">, <@ref="mwrite">.
# mreverse matshape
Output: matrix
Argument: <@var="X"> (matrix)
Returns a matrix containing the rows of <@var="X"> in reverse order. If you wish to obtain a matrix in which the columns of <@var="X"> appear in reverse order you can do:
<code>
matrix Y = mreverse(X')'
</code>
# 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 matshape
Output: matrix
Arguments: <@var="X"> (matrix)
<@var="r"> (integer)
<@var="c"> (integer)
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.
See also <@ref="cols">, <@ref="rows">, <@ref="unvech">, <@ref="vec">, <@ref="vech">.
# msortby matshape
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.
# muniform matbuild
Output: matrix
Arguments: <@var="r"> (integer)
<@var="c"> (integer)
Returns a matrix with <@var="r"> rows and <@var="c"> columns, filled with uniform (0,1) pseudo-random variates. Note: the preferred method for generating a scalar uniform r.v. is to use the <@ref="randgen1"> function.
See also <@ref="mnormal">, <@ref="uniform">.
# 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). See below for alternative formats.
If a file <@var="fname"> already exists, it will be overwritten. The return value is 0 on successful completion; if an error occurs, such as the file being unwritable, the return value will be non-zero.
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 <@pdf="the Gretl User's Guide"> for details.
Two mutually exclusive inflections of this function are available, as follows:
<indent>
• If <@var="fname"> has the suffix "<@lit=".gz">" the the file is written with gzip compression. The format is basically as described above except that the matrix elements are written in a single column, in column-major order.
</indent>
<indent>
• If <@var="fname"> has the suffix "<@lit=".bin">" the the file 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>
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.
See also <@ref="mread">.
# 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">.
# nadarwat stats
Output: series
Arguments: <@var="y"> (series)
<@var="x"> (series)
<@var="h"> (scalar)
Returns the Nadaraya–Watson nonparametric estimator of the conditional mean of <@var="y"> given <@var="x">. It returns a series holding the nonparametric estimate of <@mth="E(y"><@sub="i"><@mth="|x"><@sub="i"><@mth=")"> for each nonmissing element of the series <@var="x">.
The kernel function <@mth="K"> is given by <@mth="K = exp(-x"><@sup="2"><@mth=" / 2h)"> for <@mth="|x| < T"> and zero otherwise.
The argument <@var="h">, known as the bandwidth, is a parameter (a positive real number) given by the user. This is usually a small number: larger values of <@var="h"> make <@mth="m(x)"> smoother; a popular choice is <@mth="n"><@sup="-0.2">. More details are given in <@pdf="the Gretl User's Guide">.
The scalar <@mth="T"> is used to prevent numerical problems when the kernel function is evaluated too far away from zero and is called the trim parameter.
The trim parameter can be adjusted via the <@lit="nadarwat_trim"> setting, as a multiple of <@var="h">. The default value is 4.
The user may provide a negative value for the bandwidth: this is interpreted as conventional syntax to obtain the leave-one-out estimator, that is a variant of the estimator that does not use the <@mth="i">-th observation for evaluating <@mth="m(x"><@sub="i"><@mth=")">. This makes the Nadaraya–Watson estimator more robust numerically and its usage is normally advised when the estimator is computed for inference purposes. Of course, the bandwidth actually used is the absolute value of <@var="h">.
# 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 strings
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>
# 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.
# 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">.
# 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 pre-defined 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 the chapter on numerical methods in <@pdf="the Gretl User's Guide">. See also <@ref="BFGSmax">, <@ref="fdjac">.
# 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">.
See also <@ref="rank">, <@ref="svd">.
# 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
Argument: <@var="t"> (integer)
Returns the observation label for observation <@var="t">, where <@var="t"> is a 1-based index. The inverse function is provided by <@ref="obsnum">.
# 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 behavior is a little different, since matrices cannot contain <@lit="NA">s: 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 matbuild
Output: matrix
Arguments: <@var="r"> (integer)
<@var="c"> (integer)
Outputs a matrix with <@mth="r"> rows and <@mth="c"> columns, filled with ones.
See also <@ref="seq">, <@ref="zeros">.
# orthdev transforms
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, Weibull, 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 stats
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 data-utils
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 stats
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 stats
Output: series
Arguments: <@var="y"> (series)
<@var="mask"> (series, optional)
Only applicable if the currentl 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 stats
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 stats
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 linalg
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">.
If all the roots are real they are returned in a column vector of length <@mth="p">, otherwise a <@itl="p">×2 matrix is returned, the real parts in the first column and the imaginary parts in the second.
# polyfit filters
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 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 stats
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
Argument: <@var="A"> (symmetric matrix)
Performs a generalized variant of the Cholesky decomposition of the matrix <@var="A">, which must be positive semidefinite (but which 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.
For the case where <@var="A"> is positive definite, see <@ref="cholesky">.
# pshrink data-utils
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 stats
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="pval"> function are the standard normal, <@mth="t">, Chi square, <@mth="F">, gamma, binomial, Poisson, Weibull and Generalized Error.
See also <@ref="critical">, <@ref="invcdf">, <@ref="urcpval">, <@ref="imhof">.
# pxnobs stats
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 stats
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">)
Computes the QR decomposition of an <@itl="m">×<@itl="n"> matrix <@var="X">, that is <@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.
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">.
# 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>
• Weibull (w or W): shape, 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">.
# rank linalg
Output: integer
Argument: <@var="X"> (matrix)
Returns the rank of <@var="X">, numerically computed via the singular value decomposition. 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">.
# 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"> 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, removes (deletes) the named file. Returns 0 on successful completion, non-zero if there is no such file or the file cannot be removed.
# 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)
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.
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.
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">.
# rownames matbuild
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. For backward caompatibility, a single string may also be given as the second argument; in that case it should contain <@mth="m"> space-separated substrings.
The return value is 0 on successful completion, non-zero on error. See also <@ref="colnames">.
Example:
<code>
matrix M = {1, 2; 2, 1; 4, 1}
strings S = array(3)
S[1] = "Row1"
S[2] = "Row2"
S[3] = "Row3"
rownames(M, S)
print M
</code>
# rows matshape
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">.
# sd stats
Output: scalar or series
Argument: <@var="x"> (series or list)
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">, or <@lit="NA"> if there are any missing values at <@mth="t">.
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">). 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.
# selifc matshape
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 matshape
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 matbuild
Output: row vector
Arguments: <@var="a"> (integer)
<@var="b"> (integer)
<@var="k"> (integer, optional)
Given only two arguments, returns a row vector filled with consecutive integers, with <@var="a"> as first element and <@var="b"> last. If <@var="a"> is greater than <@var="b"> the sequence will be decreasing.
If the third argument is given, returns a row vector containing a sequence of integers 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 a positive integer.
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">).
# 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 the chapter on numerical methods in <@pdf="the Gretl User's Guide">. 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.
# sort matshape
Output: same type as input
Argument: <@var="x"> (series or vector)
Sorts <@var="x"> in ascending order, skipping observations with missing values when <@mth="x"> is a series. 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">.
# 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">. See the help for the <@xrf="printf"> command for details regarding the format and other arguments.
# 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.
# 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 and, since matrices cannot contain <@lit="NA">, negative values generate an error. For the "matrix square root" see <@ref="cholesky">.
# sscanf strings
Output: integer
Arguments: <@var="src"> (string)
<@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.
<@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 pre-defined 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; and <@lit="%m"> for matrices. You may insert a positive integer after the percent sign: this sets the maximum number of characters to read for the given conversion (or the maximum number of rows in the case of matrix 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="source"> to an integer, if possible; <@lit="%*g"> skips as many characters in <@var="source"> as could be converted to a single floating-point number.
Matrix conversion works thus: 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 to read can be limited as described above.
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 examples follow:
<code>
scalar x
scalar y
sscanf("123456", "%3d%3d", x, y)
sprintf S, "1 2 3 4\n5 6 7 8"
S
matrix m
sscanf(S, "%m", 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">.
# 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. See also <@ref="strvals">.
The value returned is zero on success or a positive error code on error.
# strlen strings
Output: integer
Argument: <@var="s"> (string)
Returns the number of characters in the string <@var="s">. Note that this does not necessarily equal the number of bytes if some characters are outside of the printable-ASCII range.
Example:
<code>
string s = "regression"
scalar number = strlen(s)
print number
</code>
# 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) ...">
# strsplit strings
Output: string or array of strings
Arguments: <@var="s"> (string)
<@var="i"> (integer, optional)
With no second argument, returns the array of strings that results from the splitting of <@var="s"> on white space.
If the second argument is provided, returns space-separated element <@var="i"> from the string <@var="s">. The index <@var="i"> is 1-based, and it is an error if <@var="i"> is less than 1. In case <@var="s"> contains no spaces and <@var="i"> equals 1, a copy of the entire input string is returned; otherwise, in case <@var="i"> exceeds the number of space-separated elements an empty string is returned.
Examples:
<code>
string basket = "banana apple jackfruit orange"
strings fruits = strsplit(basket)
eval fruits[1]
eval fruits[2]
eval fruits[3]
eval fruits[4]
string favorite = strsplit(basket, 3)
eval favorite
</code>
# strstr strings
Output: string
Arguments: <@var="s1"> (string)
<@var="s2"> (string)
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>
# 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)
<@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
Argument: <@var="y"> (series)
If the series <@var="y"> is string-valued, returns an array containing all its distinct values, ordered by the associated numerical values starting at 1. If <@var="y"> is not string-valued an empty strings array is returned. See also <@ref="stringify">.
# substr strings
Output: string
Arguments: <@var="s"> (string)
<@var="start"> (integer)
<@var="end"> (integer)
Returns a substring of <@var="s">, from the character with (1-based) index <@var="start"> to that with index <@var="end">, inclusive.
Examples:
<code>
string s1 = "Hello, Gretl!"
string s2 = substr(s1, 8, 12)
print s2
string s3 = substr("Hello, Gretl!", 8, 12)
print s3
</code>
# sum stats
Output: scalar or series
Argument: <@var="x"> (series, matrix or list)
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">, or <@lit="NA"> if there are any missing values at <@mth="t">.
# 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"> is 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">.
# 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">.
# toepsolv linalg
Output: column vector
Arguments: <@var="c"> (vector)
<@var="r"> (vector)
<@var="b"> (vector)
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.
# 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'">.
# trimr matshape
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">.
# 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 function <@ref="inbundle">. The value returned is one of "scalar", "series", "matrix", "string", "bundle", "array" 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 elements of <@var="x">, not sorted but in their order of appearance. See <@ref="values"> for a variant that sorts the elements.
# unvech matbuild
Output: square matrix
Argument: <@var="v"> (vector)
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">.
See also <@ref="mshape">, <@ref="vech">.
# upper matbuild
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. 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
Argument: <@var="x"> (series or list)
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">, or <@lit="NA"> if there are any missing values at <@mth="t">.
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 linalg
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 gretl's <@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 matbuild
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 matbuild
Output: column vector
Argument: <@var="A"> (square matrix)
Returns in a column vector the elements of <@var="A"> on and above the diagonal. Typically, this function is used on symmetric matrices; in this case, it can be undone by the function <@ref="unvech">. See also <@ref="vec">.
# 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.
# wmean stats
Output: series
Arguments: <@var="Y"> (list)
<@var="W"> (list)
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.
See also <@ref="wsd">, <@ref="wvar">.
# wsd stats
Output: series
Arguments: <@var="Y"> (list)
<@var="W"> (list)
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.
See also <@ref="wmean">, <@ref="wvar">.
# wvar stats
Output: series
Arguments: <@var="X"> (list)
<@var="W"> (list)
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.
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">.
# zeromiss data-utils
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 matbuild
Output: matrix
Arguments: <@var="r"> (integer)
<@var="c"> (integer)
Outputs a zero matrix with <@mth="r"> rows and <@mth="c"> columns. See also <@ref="ones">, <@ref="seq">.
|