<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>aptech &#8211; Aptech</title>
	<atom:link href="https://www.aptech.com/blog/author/ebendesign/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.aptech.com</link>
	<description>GAUSS Software - Fastest Platform for Data Analytics</description>
	<lastBuildDate>Tue, 23 Apr 2024 20:22:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>GAUSS 23</title>
		<link>https://www.aptech.com/blog/gauss23/</link>
					<comments>https://www.aptech.com/blog/gauss23/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Wed, 07 Dec 2022 15:11:23 +0000</pubDate>
				<category><![CDATA[Releases]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11583074</guid>

					<description><![CDATA[The new GAUSS 23 is the most practical GAUSS yet! It's built with the intention to save you time on everyday research tasks like finding, importing, and modeling data. 

Learn about new features including:
<ul>
<li>New FRED and DBnomics data integrations.</li>
<li>Simplified data loading with intelligent type detection.</li>
<li>First-class dataframe storage.</li>
<li>Expanded quantile regressions.</li>
<li>Kernel density estimation.</li>
<li>and more ...</li>
<ul>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>The new GAUSS 23 is the most practical GAUSS yet! It's built with the intention to save you time on everyday research tasks like finding, importing, and modeling data. </p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/12/Shutterstock_1893823846-1-scaled.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/12/Shutterstock_1893823846-1-scaled.jpg" alt="People working at a computer." width="2560" height="1229" class="aligncenter size-full wp-image-11583207" /></a></p>
<h2 id="data-at-your-fingertips">Data at Your Fingertips</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/11/fred-load-ppi-w-logos-2.png"><img src="https://www.aptech.com/wp-content/uploads/2022/11/fred-load-ppi-w-logos-2.png" alt="Load data from DBnomics and FRED to GAUSS." width="656" height="394" class="aligncenter size-full wp-image-11583148" /></a></p>
<ul>
<li>Access millions of global economic and financial data series with FRED and DBnomics integration. </li>
<li>Aggregate, filter, sort, and transform FRED  data series during import. </li>
<li>Search FRED series from GAUSS.</li>
</ul>
<h3 id="load-data-from-anywhere-on-the-internet">Load Data from Anywhere on the Internet</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load an Excel file from the aptech website
file_url = "https://www.aptech.com/wp-content/uploads/2019/03/skincancer2.xlsx";
skin_cancer = loadd(file_url);

// Print the first 5 rows of the dataframe
head(skin_cancer);</code></pre>
<pre>       State       Lat       Mort      Ocean        Long
     Alabama        33        219          1          87
     Arizona      34.5        160          0         112
    Arkansas        35        170          0        92.5
  California      37.5        182          1       119.5
    Colorado        39        149          0       105.5</pre>
<h2 id="simplified-data-loading-with">Simplified Data Loading with...</h2>
<h3 id="automatic-type-detection">Automatic Type Detection</h3>
<p><strong>Previous versions</strong> required formula strings with keywords to specify date, string, and categorical variables from some file types.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/12/g23-load-variables-1.png"><img src="https://www.aptech.com/wp-content/uploads/2022/12/g23-load-variables-1.png" alt="Code to load variables into GAUSS." width="1600" height="390" class="aligncenter size-full wp-image-11583209" /></a></p>
<p><strong>Smart data type detection in GAUSS 23</strong> figures out the variable type so you do not have to specify it manually. Automatically detects nearly 40 popular date formats.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/12/Screen-Shot-2022-12-06-at-8.12.15-AM-1.png"><img src="https://www.aptech.com/wp-content/uploads/2022/12/Screen-Shot-2022-12-06-at-8.12.15-AM-1.png" alt="" width="1600" height="160" class="aligncenter size-full wp-image-11583201" /></a></p>
<h3 id="automatic-header-and-delimiter-detection">Automatic Header and Delimiter Detection</h3>
<p>Replace old code like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">load X[127,4] = mydata.txt;</code></pre>
<p>with</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">X = loadd("mydata.txt");</code></pre>
<p>Automatically handles</p>
<ul>
<li>Present or absent header row.</li>
<li>Delimiter (tab, comma, semi-colon or space).</li>
<li>Number of rows and columns.</li>
<li>Variable types.</li>
</ul>
<h2 id="first-class-dataframe-storage">First-Class Dataframe Storage</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/11/g23-gdat-save-load-6.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/11/g23-gdat-save-load-6.jpg" alt="Loading and saving GAUSS dataframes." width="580" height="430" class="aligncenter size-full wp-image-11583152" /></a></p>
<p>No new code to learn, just use the <code>.gdat</code> file extension with <a href="https://docs.aptech.com/gauss/loadd.html"><code>loadd</code></a> and <a href="https://docs.aptech.com/gauss/saved.html"><code>saved</code></a> to load and store your dataframes.</p>
<p><br/></p>
<hr>
<div style="text-align:center">Questions? <a href="https://www.aptech.com/book-an-expert">Book some time</a>  with one of our friendly GAUSS experts</div>
<hr>
<h2 id="expanded-quantile-regressions">Expanded Quantile Regressions</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2019/01/quantile_regression_percent_below.png"><img src="https://www.aptech.com/wp-content/uploads/2019/01/quantile_regression_percent_below.png" alt="Graph of quantile regression." width="600" height="300" class="aligncenter size-full wp-image-19342" /></a></p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">hitters = loadd("islr_hitters.xlsx"); 

tau = 0.90;

call quantileFit(hitters, "ln(salary) ~ AtBat + Hits + HmRun", tau);</code></pre>
<pre>Linear quantile regression

===============================================================================
Valid cases:                 263            Dependent variable:     ln_salary_
Missing cases:                 0               Deletion method:           None
Number variables:              3                       DF model              3
DF residuals                 259<br />
===============================================================================

                 Name    Coeff.  Standard   t-value  P &gt;|t|      lb       ub
                                  Error<br />
-------------------------------------------------------------------------------
Tau = 0.90<br />

              CONSTANT    6.285    0.194   32.433    0.0000    5.905    6.664
                 AtBat   -0.001    0.002   -0.737    0.4621   -0.004    0.002
                  Hits    0.008    0.005    1.526    0.1281   -0.002    0.018
                 HmRun    0.017    0.009    1.951    0.0521   -0.000    0.034</pre>
<ul>
<li>New kernel estimated variance-covariance matrix. </li>
<li>Up to 4x speed improvement. </li>
<li>Expanded model diagnostics including pseudo R-squared, coefficient t-statistics and p-values, and degrees of freedom.</li>
</ul>
<h2 id="kernel-density-estimations">Kernel Density Estimations</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/11/g23-kernel-density.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/11/g23-kernel-density.jpg" alt="" width="600" height="400" class="aligncenter size-full wp-image-11583097" /></a></p>
<ul>
<li>Estimate unknown probability functions with 13 available kernels. </li>
<li>Automatic or user-specified bandwidth.</li>
<li>Kernel density plots with easy-to-use options for customization. </li>
</ul>
<hr>
<div style="text-align:center"><a href="https://www.aptech.com/request-demo/">Start your free trial!</a></div>
<hr>
<h2 id="improved-covariance-computations">Improved Covariance Computations</h2>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load data
fname = getGAUSShome("examples/auto2.dta");
auto = loadd(fname);

// Declare control structure
struct olsmtControl ctl;
ctl = olsmtControlCreate();

// Turn on residuals
ctl.res = 1;

// Turn on HAC errors
ctl.cov = "hac";

call olsmt(auto, "mpg ~ weight + foreign", ctl); </code></pre>
<pre>Valid cases:                    74      Dependent variable:                 mpg
Missing cases:                   0      Deletion method:                   None
Total SS:                 2443.459      Degrees of freedom:                  71
R-squared:                   0.663      Rbar-squared:                     0.653
Residual SS:               824.172      Std error of est:                 3.407
F(2,71):                    69.748      Probability of F:                 0.000
Durbin-Watson:               2.421

                                  Std                 Prob      Std    Cor with
Variable            Estimate     Error     t-value    &gt;|t|      Est    Dep Var
-------------------------------------------------------------------------------

CONSTANT             41.6797    1.8989     21.95     0.000      ---         ---
weight              -0.00659    0.0006    -11.99     0.000   -0.885   -0.807175
foreign: Foreign    -1.65003    0.9071    -1.819     0.073   -0.131    0.393397

Note: HAC robust standard errors reported</pre>
<ul>
<li>New procedure for computing Newey-West HAC robust standard errors. </li>
<li>All robust covariance procedures now include the option to turn off small sample corrections. </li>
<li>Expanded dataframe and formula string compatibility. </li>
</ul>
<h2 id="new-functions-for-data-cleaning-and-exploration">New Functions for Data Cleaning and Exploration</h2>
<h3 id="between"><a href="https://docs.aptech.com/gauss/between.html">between</a></h3>
<p>Returns a binary vector indicating which observations fall in a specified range. It can be used with <a href="https://docs.aptech.com/gauss/selif.html"><code>selif</code></a> to select rows. Dates and ordinal categorical columns are supported.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Return a 1 if the observation is between the listed dates
match = between(unemp[.,"DATE"], "2020-03", "2020-08");

// Select the matching observations
unemp = selif(unemp, match);</code></pre>
<pre>            DATE        UNRATE
      2020-03-01        4.4000
      2020-04-01        14.700
      2020-05-01        13.200
      2020-06-01        11.000
      2020-07-01        10.200
      2020-08-01        8.4000</pre>
<h3 id="where"><a href="https://docs.aptech.com/gauss/where.html">where</a></h3>
<p>Provides a convenient and intuitive way to combine or modify data. It returns elements from either <code>a</code> or <code>b</code> depending upon <code>condition</code>.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Daily hotel room price
hotel_price = { 238, 405, 405, 329, 238 };

// Daily temperature forecast
temperature = { 89, 94, 110, 103, 97 };

// Decrease the price by 10% if the
// temperature will be more than 100 degrees
new_price = where(temperature .&gt; 100,
                hotel_price .* 0.9,
                hotel_price);</code></pre>
<pre>new_price = 238 405 364.50 296.10 238</pre>
<ul>
<li>Explore sample symmetry and tails with <a href="https://docs.aptech.com/gauss/skewness.html"><code>skewness</code></a> and <a href="https://docs.aptech.com/gauss/kurtosis.html"><code>kurtosis</code></a> functions. </li>
<li>Test for normality using the new <a href="https://docs.aptech.com/gauss/jarquebera.html"><code>JarqueBera</code></a> function.</li>
</ul>
<h2 id="speed-ups-and-efficiency-improvements">Speed-ups and Efficiency Improvements</h2>
<ul>
<li>Up to 10x speed-up and 50% decrease in memory usage for lag creation with <a href="https://docs.aptech.com/gauss/shiftc.html"><code>shiftc</code></a> and <a href="https://docs.aptech.com/gauss/lagn.html"><code>lagn</code></a>.</li>
<li>Up to 2x speed-up (or more for large data) and 50% decrease in memory usage for <a href="https://docs.aptech.com/gauss/missmissrv.html"><code>miss</code></a>, <a href="https://docs.aptech.com/gauss/missmissrv.html"><code>missrv</code></a>.</li>
<li>Up to 2x speed-up (or more for large data) and 50% decrease in memory usage for element-by-element mathematical (<code>+</code>, <code>-</code>, <code>.*</code>, <code>./</code>), relational (<code>.&gt;</code>, <code>.&lt;</code>, <code>.&gt;=</code>, <code>.&lt;=</code>, <code>.==</code>, <code>.!=</code>) and logical (<code>.and</code>, <code>.not</code>, <code>.or</code>, <code>.xor</code>) operators.</li>
<li>Up to 100x speed-up for some cases with <a href="https://docs.aptech.com/gauss/indsav.html"><code>indsav</code></a>.</li>
<li>Up to 40% speed-up for <a href="https://docs.aptech.com/gauss/reclassify.html"><code>reclassify</code></a>.</li>
<li>Up to 3x speed-up for loading Excel® files with <code>loadd</code> and the Data Import Window.</li>
</ul>
<h3 id="conclusion">Conclusion</h3>
<p>For a complete list of all GAUSS 23 offers please see the complete <a href="https://docs.aptech.com/gauss/changelog.html" target="_blank" rel="noopener">changelog</a>. </p>
<div style="text-align:center;background-color:#455560;color:#FFFFFF">
<hr>
<h3 id="discover-how-gauss-23-can-help-you-make-your-mark">Discover how GAUSS 23 can help you make your mark</h3>
 
<div class="lp-cta">
    <a href="https://www.aptech.com/book-an-expert" class="btn btn-primary">Talk with an expert</a>
    <a href="https://www.aptech.com/request-quote/" class="btn btn-primary btn-quote">Request pricing</a>
</div><hr>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/gauss23/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Introduction to Efficient Creation of Detailed Plots</title>
		<link>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/</link>
					<comments>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 27 Sep 2022 16:26:33 +0000</pubDate>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11582941</guid>

					<description><![CDATA[A few weeks ago, we showed you how to create a detailed plot from a recent article in the American Economic Review. That article contained several plots that contain quite a bit of similar and stylized formatting. Today we will show you how to <i>efficiently</i> create two of these graphs.

Our main goals are to get you thinking about code reuse and how it can help you:

<ul>
<li> Get more results from your limited research time.</li>
<li>Avoid the frustration that comes from growing mountains of spaghetti code.</li>
</ul>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>A few weeks ago, we showed you how to create a detailed plot from a recent article in the American Economic Review. That article contained several plots that contain quite a bit of similar and stylized formatting. Today we will show you how to <em>efficiently</em> create two of these graphs.</p>
<p>Our main goals are to get you thinking about code reuse and how it can help you:</p>
<ul>
<li>Get more results from your limited research time.</li>
<li>Avoid the frustration that comes from growing mountains of spaghetti code.</li>
</ul>
<div class="alert alert-info" role="alert">If you missed it, be sure to check out our original blog on this topic, <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/" target="_blank" rel="noopener">Advanced Formatting Techniques for Creating AER Quality Plots</a>. </div>
<h2 id="our-graphs">Our Graphs</h2>
<p>This is what we will create today. As you can see they share many style attributes. This gives us a great opportunity to reuse code.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/09/gblog-hetboombust1x2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/09/gblog-hetboombust1x2.jpg" alt="Line plots from an American Economic Review article created by GAUSS." width="1000" height="400" class="aligncenter size-full wp-image-11582942" /></a></p>
<p>You can <a href="https://raw.githubusercontent.com/aptech/gauss_blog/master/programming/introduction-efficient-creation-plots-9.27.22/rationing.csv" target="_blank" rel="noopener">download the data here</a>. </p>
<h2 id="our-initial-code">Our Initial Code</h2>
<p>This is not a massive amount of code and many of you might be tempted to just copy and paste this code and make the minor modifications needed to get your desired result. I completely understand. Your biggest problem is probably a lack of time, so productivity is paramount.</p>
<p>While it might feel like this is a shortcut, it will saddle you with technical debt. Technical debt is just a fancy term that describes the stress, frustration, and time-wasting that inevitably occurs when you take shortcuts like this.</p>
<p>Not only will this save you pain, but it might save you some embarrassment as well. These sorts of mundane issues are real drivers of the replication crises in research today.</p>
<p>Your research is important and I know you want to do it right, so let's get started! </p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Default settings
struct plotControl plt;
plt = plotGetDefaults("xy");

// Font
plotSetFonts(&amp;plt, "all", "roboto", 14);

// Legend
plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);

// Main line settings
clrs = getColorPalette("set2");
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

// Axes outline (spine)
plotSetOutlineEnabled(&amp;plt, 1);

// X-axis
plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

// Y-axis
plotSetYLabel(&amp;plt, "interest rate");

// Draw main plot
plotXY(plt, int_rate, "high + low ~ x");

// Style and add vertical lines
plotSetLinePen(&amp;plt, 1, "#CCC", 2);
plotAddVLine(plt, ks);

// Style text boxes
struct plotAnnotation ant;
ant = annotationGetDefaults();
annotationSetTextInterpreter(&amp;ant, "latex");
annotationSetLinePen(&amp;ant, 0, "", -1);
annotationSetFont(&amp;ant, "", 14, "#3333");
annotationSetBkd(&amp;ant, "", 0);

// Add text boxes
plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="initial-code-simplification">Initial Code Simplification</h2>
<p>We will start by creating a <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/" target="_blank" rel="noopener">procedure</a> to hold some of the plot styling functions that we want to repeat and apply them to the first plot only. Then we will add the data for the second plot.</p>
<p>It looks like all of the styling applied before the call to <a href="https://docs.aptech.com/gauss/plotxy.html" target="_blank" rel="noopener"><code>plotXY</code></a> will be the same in both plots, but the y-axis label text is different. So, let's create a procedure that will apply the main settings:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Declare plotControl structure
struct plotControl plt;

// Fill with defaults for this project
plt = pltDefaults();

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "interest rate");

// Draw first plot
plotXY(plt, int_rate, "high + low ~ x");

proc (1) = pltDefaults();
    local clrs;

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Font
    plotSetFonts(&amp;plt, "all", "roboto", 14);

    // Legend
    plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
    plotSetLegendBkd(&amp;plt, 0);

    // Main line settings
    clrs = getColorPalette("set2");
    plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

    // Axes outline (spine)
    plotSetOutlineEnabled(&amp;plt, 1);

    // X-axis
    plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
    plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

    retp(plt);
endp;
</code></pre>
<p>While this code is slightly longer when drawing just one plot, it will save us when we add the next plot. Before we do that, we need to address the <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#add-vertical-lines" target="_blank" rel="noopener">vertical lines</a> and <a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#add-text-annotations" target="_blank" rel="noopener">annotations</a>.</p>
<h2 id="simplifying-the-annotations">Simplifying the Annotations</h2>
<p>Looking over the plots at the top of this article shows us that the vertical lines and the omega text boxes all depend on the <code>ks</code> vector. Since they seem to be intertwined, it is probably safe to put them in one procedure. </p>
<p>The simplest thing to do would be to add all the annotation code to a single procedure like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    // Style text boxes
    struct plotAnnotation ant;
    ant = annotationGetDefaults();
    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<p>and then call that procedure right after <code>plotXY</code>. In this case, it is not a bad place to start. However, since we are in learning mode, let's pretend that we were going to create more graphs in this file that would add text boxes with the same styling, but would use different greek letters and would be located in a different place in the graph.</p>
<p>In that case, we would probably want to separate the text box styling from the text box drawing, like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (1) = textBoxDefaults();
    struct plotAnnotation ant;
    ant = annotationGetDefaults();

    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    retp(ant);
endp;

proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    struct plotAnnotation ant;
    ant = textBoxDefaults();

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<h3 id="conclusion-and-final-code">Conclusion and final code</h3>
<p>Below is the final code to create the graphs from the top of this blog. This isn't designed to show you the best way to write this code, but rather to get you started with the idea of code reuse.</p>
<p>Software engineers sometimes use the acronym DRY — Don't Repeat Yourself. While that is a great practice, even just repeating yourself less often will bring you great rewards.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");
tail(int_rate);

rationing = loadd("rationing.csv");
tail(rationing);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 1000 | 400);

// Declare plotControl structure and
// fill with defaults for this project
struct plotControl plt;
plt = pltDefaults();

/*
** Interest rate plot
*/

// Create grid for multiple plots
plotLayout(1,2,1);

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "interest rate");

// Draw first plot
plotXY(plt, int_rate, "high + low ~ x");
pltAddOmegas(ks);

/*
** Rationing plot
*/

// Create grid for multiple plots
plotLayout(1,2,2);

// Set y-axis label for first plot
plotSetYLabel(&amp;plt, "rationing");

// Draw first plot
plotXY(plt, rationing, "high + low ~ x");
pltAddOmegas(ks);

proc (1) = pltDefaults();
    local clrs;

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Font
    plotSetFonts(&amp;plt, "all", "roboto", 14);

    // Legend
    plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
    plotSetLegendBkd(&amp;plt, 0);

    // Main line settings
    clrs = getColorPalette("set2");
    plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

    // Axes outline (spine)
    plotSetOutlineEnabled(&amp;plt, 1);

    // X-axis
    plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
    plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

    retp(plt);
endp;

proc (1) = textBoxDefaults();
    struct plotAnnotation ant;
    ant = annotationGetDefaults();

    annotationSetTextInterpreter(&amp;ant, "latex");
    annotationSetLinePen(&amp;ant, 0, "", -1);
    annotationSetFont(&amp;ant, "", 14, "#3333");
    annotationSetBkd(&amp;ant, "", 0);

    retp(ant);
endp;

proc (0) = pltAddOmegas(ks);

    struct plotControl plt;
    plt = plotGetDefaults("xy");

    // Style and add vertical lines
    plotSetLinePen(&amp;plt, 1, "#CCC", 2);
    plotAddVLine(plt, ks);

    struct plotAnnotation ant;
    ant = textBoxDefaults();

    // Add text boxes
    plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
    plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
    plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);
endp;</code></pre>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/" target="_blank" rel="noopener">Advanced Formatting Techniques for Creating AER Quality Plots.</a></li>
<li><a href="https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/" target="_blank" rel="noopener">Visualizing COVID-19 Panel Data With GAUSS 22.</a> </li>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/" target="_blank" rel="noopener">How to Mix, Match and Style Different Graph Types.</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/introduction-to-efficient-creation-of-detailed-plots/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Advanced Formatting Techniques for Creating AER Quality Plots</title>
		<link>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/</link>
					<comments>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/#comments</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Wed, 27 Jul 2022 21:18:24 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11582603</guid>

					<description><![CDATA[This blog will show you how to reproduce one of the graphs from a paper in the June 2022 issue of the American Economic Review. You will learn how to:
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li> Set the font for all or a subset of the graph text elements.</li>
<li> Set the size of your graph.</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today's blog will show you how to reproduce one of the graphs from a paper in the June 2022 issue of the journal, <a href="https://www.aeaweb.org/journals/aer" target="_blank" rel="noopener">American Economic Review</a>. You will learn how to:</p>
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li>Set the font for all or a subset of the graph text elements.</li>
<li>Set the size of your graph.</li>
</ol>
<h2 id="the-graph-and-data">The Graph and Data</h2>
<p>Below is the graph that we are going to create. It is adapted from a recent paper in the American Economic Review. You can <a href="https://raw.githubusercontent.com/aptech/gauss_blog/master/graphics/advanced-formatting-aer-quality/int_rate.csv" target="_blank" rel="noopener">download the data here</a>.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-final.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-final.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582641" /></a></p>
<h2 id="load-and-preview-data">Load and Preview Data</h2>
<p>Our first step will be to <a href="https://www.aptech.com/resources/tutorials/loading-variables-from-a-file/" target="_blank" rel="noopener">load the data</a> and take a quick look at it.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Load all variables from 'int_rate.csv'
int_rate = loadd("int_rate.csv");

// Print the first 5 observations of 'int_rate'
print "First 5 observations:";
head(int_rate);

// Print the last 5 observations of 'int_rate'
print "Last 5 observations:";
tail(int_rate);

// Print descriptive statistics of our variables
call dstatmt(int_rate);</code></pre>
<p>This will give us the following results:</p>
<pre>First 5 observations:

               x             high              low
   0.00010000000       0.17140598        0.0000000
   0.00020000000       0.17140598        0.0000000
   0.00030000000       0.17140598        0.0000000
   0.00040000000       0.17140598        0.0000000
   0.00050000000       0.17140598        0.0000000

Last 5 observations:

               x             high              low
      0.99950000       0.17140598       0.23012203
      0.99960000       0.17140598       0.23012203
      0.99970000       0.17140598       0.23012203
      0.99980000       0.17140598       0.23012203
      0.99990000       0.17140598       0.23012203

-------------------------------------------------------------------------------
Variable     Mean    Std Dev     Variance    Minimum    Maximum   Valid Missing
-------------------------------------------------------------------------------

x             0.5      0.289       0.0833      1e-4      0.999    9999    0
high       0.1714   1.04e-07     1.08e-14     0.171      0.171    9999    0
low       0.09374      0.108       0.0116         0      0.230    9999    0</pre>
<h2 id="initial-graphs">Initial Graphs</h2>
<p>Our first graphs will use the default GAUSS styling. We will create one graph indexing our <code>x</code> and <code>y</code> variables and another using a <a href="https://www.aptech.com/resources/tutorials/formula-string-syntax/" target="_blank" rel="noopener">formula string</a>.</p>
<h3 id="indexing">Indexing</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-index.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-index.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582627" /></a></p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set our graph size to 500x400 pixels
plotCanvasSize("px", 500 | 400);

// Use indexing to select the 'x' and 'y' variables
plotXY(int_rate[.,"x"], int_rate[.,"high" "low"]);</code></pre>
<h3 id="formula-string">Formula string</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-formula.png"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-unstyled-formula.png" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582634" /></a></p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set our graph size to 500x400 pixels
plotCanvasSize("px", 500 | 400);

// Specify the 'x' and 'y' variables using a formula string
plotXY(int_rate, "high + low ~ x");</code></pre>
<p>When we use a formula string with our plot functions, it tells GAUSS that we want to use the information from the <a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">dataframe</a>.</p>
<p>When using a formula string in plots:</p>
<ul>
<li>The tilde symbol, <code>~</code>, separates the <code>y</code> variables on the left from the <code>x</code> variable(s) on the right. </li>
<li>If there is a single <code>y</code> variable, GAUSS will use that variable name to label the <code>y</code> axis. If there is more than one <code>y</code> variable, then the variable names will be added to the legend.</li>
<li>The name of the <code>x</code> variable will be used to label the x-axis.</li>
</ul>
<p>While this may not always be the information we want to be displayed in our final plot, it makes it convenient to quickly create graphs that are easier to interpret.</p>
<h2 id="plot-styling">Plot Styling</h2>
<p>Fp
Next, we will adjust the styling to match our intended final plot.</p>
<p>To programmatically style our graph, the first thing we need to do is to create a <code>plotControl</code> structure and fill it with default values.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">struct plotControl plt;
plt = plotGetDefault("xy");</code></pre>
<h3 id="legend-styling">Legend styling</h3>
<p>After the pointer to the <code>plotControl</code> structure we want to modify, <code>&amp;plt</code>, the function <a href="https://docs.aptech.com/gauss/plotsetlegend.html" target="_blank" rel="noopener"><code>plotSetLegend</code></a> takes one required input and two optional ones.</p>
<ol>
<li>
<p><strong>Legend text</strong>: This controls the text that will be displayed in the legend. We want GAUSS to use the variable names from our input. Therefore, below, we set this to an empty string, <code>""</code>. This tells GAUSS that we do not want to modify the default behavior of the legend text.</p>
<p>As we mentioned earlier, the default behavior for a graph created with a formula string with more than one <code>y</code> variable is to use the <code>y</code> variable names as the legend text elements.</p>
</li>
<li>
<p><strong>Legend location</strong>: This input can be a string with text location specifications, or a 2x1 vector with the <code>x</code> and <code>y</code> coordinates for the location of the top-left corner of the legend.</p>
</li>
<li><strong>Legend orientation</strong>: This input specifies whether the legend position should be stacked vertically or horizontally. We set it to <code>1</code> to indicate a vertical arrangement. It may help to remember that a <code>1</code> is a vertical essentially a vertical mark.</li>
</ol>
<p>The first input to <a href="https://docs.aptech.com/gauss/plotsetlegendbkd.html" target="_blank" rel="noopener"><code>plotSetLegendBkd</code></a>, after the <code>plotControl</code> structure pointer, controls the legend opacity. We set it to be 0% opaque, or 100% transparent.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);</code></pre>
<h3 id="font-styling">Font styling</h3>
<p><a href="https://docs.aptech.com/gauss/plotsetfonts.html" target="_blank" rel="noopener"><code>plotSetFonts</code></a> provides a convenient way to set the font family, size, and color for any subset of the text in your graph. Below we set the font for 'all' of the text in the plot. However, there are many other options, including: <code>"axes"</code>, <code>"legend"</code>, <code>"legend_title"</code>, <code>"title"</code>, <code>"ticks"</code> and many more.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetFonts(&amp;plt, "all", "roboto", 14);</code></pre>
<h3 id="x-axis-label">X-axis label</h3>
<p><a href="https://docs.aptech.com/gauss/plotsettextinterpreter.html" target="_blank" rel="noopener"><code>plotSetTextInterpreter</code></a> tells GAUSS whether you would like text labels to be interpreted as:</p>
<ul>
<li>HTML</li>
<li>LaTeX</li>
<li>Plain text</li>
</ul>
<p>Like <code>plotSetFonts</code>, it allows you to specify many different locations, or even, <code>"all"</code>. Below, we set the x-axis to be interpreted as LaTeX and then use LaTeX in our x-axis label.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");</code></pre>
<h3 id="main-line-styling">Main line styling</h3>
<p>The &quot;set2&quot; <a href="https://docs.aptech.com/gauss/getcolorpalette.html" target="_blank" rel="noopener">color palette</a> contains eight colors:<br/>
<span><svg height="24" width="192">    <rect fill="rgb(102,194,165)" width="24" height="24" x="0"></rect>    <rect fill="rgb(252,141,98)" width="24" height="24" x="24"></rect>    <rect fill="rgb(141,160,203)" width="24" height="24" x="48"></rect>    <rect fill="rgb(231,138,195)" width="24" height="24" x="72"></rect>    <rect fill="rgb(166,216,84)" width="24" height="24" x="96"></rect>    <rect fill="rgb(255,217,47)" width="24" height="24" x="120"></rect>    <rect fill="rgb(229,196,148)" width="24" height="24" x="144"></rect>    <rect fill="rgb(179,179,179)" width="24" height="24" x="168"></span></p>
<p>We want to use the third color for our first series, &quot;high&quot;, and the second color for our second series, &quot;low&quot;.</p>
<p>Additionally, we set the line width to <code>4</code> pixels and set the line style to <code>1</code> and <code>3</code> respectively. One indicates a solid line and three is for a dotted line.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">clrs = getColorPalette("set2");

// Set the line width, line colors, and line style
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);</code></pre>
<h3 id="axes-outline">Axes outline</h3>
<p>The axes outline, or spine as they are called by other libraries, controls the lines around the edges of the data area. By default, the bottom x-axis and left y-axis are enabled. The code below will also turn on the lines on the top x-axis and right y-axis.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotSetOutlineEnabled(&amp;plt, 1);</code></pre>
<h3 id="graph-before-annotations">Graph before annotations</h3>
<p>If we draw the graph, using our previous styling and a formula string as shown below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotXY(plt, int_rate, "high + low ~ x");</code></pre>
<p>we get the following plot:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-styled-wo-annotations.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-hetboombust-1-styled-wo-annotations.jpg" alt="" width="500" height="400" class="aligncenter size-full wp-image-11582659" /></a></p>
<h2 id="add-vertical-lines">Add Vertical Lines</h2>
<h3 id="line-styling">Line styling</h3>
<p>We will continue with the <code>plotControl</code> structure we created earlier and modify the line settings to match the vertical lines from the graph we are trying to reproduce.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Set lines to be: 1 pixel wide, light gray (#CCC) and dashed style (2)
plotSetLinePen(&amp;plt, 1, "#CCC", 2);</code></pre>
<h3 id="draw-the-lines">Draw the lines</h3>
<p>We add the vertical lines using <a href="https://docs.aptech.com/gauss/plotaddvline.html" target="_blank" rel="noopener"><code>plotAddVLine</code></a>. <code>plotAddVLine</code> takes an optional <code>plotControl</code> structure as the first input and then a vector of one or more x-axis locations at which to draw the vertical spanning lines.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// The x-axis locations for the vertical lines
ks = { 0.517, 0.653, 0.781 };

plotAddVLine(plt, ks);</code></pre>
<h2 id="add-text-annotations">Add Text Annotations</h2>
<h3 id="style-text-boxes">Style text boxes</h3>
<p>The annotation styling functions use a <code>plotAnnotation</code> structure but work very similarly to the main plot styling (<code>plotSet</code>) functions. Therefore, we will just use comments to describe their actions.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">struct plotAnnotation ant;
ant = annotationGetDefaults();

// Set text to be interpreted as LaTeX
annotationSetTextInterpreter(&amp;ant, "latex");

// Turn off the text box bounding line, by setting:
//     line-width=0, line-color="" (ignore), line-style=-1 (no line)
annotationSetLinePen(&amp;ant, 0, "", -1);

// Leave the font-family as default, "",
// Set the font-size to 14 points and the color to a
// dark gray, #333
annotationSetFont(&amp;ant, "", 14, "#3333");

// Leave the annotation background color, "".
// Set the opacity to 0% (100% transparent)
annotationSetBkd(&amp;ant, "", 0);</code></pre>
<h3 id="draw-the-text-boxes">Draw the text boxes</h3>
<p>After the optional <code>plotAnnotation</code> structure, <a href="https://docs.aptech.com/gauss/plotaddtextbox.html" target="_blank" rel="noopener"><code>plotAddTextbox</code></a> takes 3 input arguments:</p>
<ol>
<li><strong>The text to display.</strong><br/></li>
<li><strong>The x-axis coordinate.</strong><br/></li>
<li><strong>The y-axis coordinate.</strong><br/></li>
</ol>
<p>By default, the x and y-axis coordinates specify the location of the top-left of the bounding box that contains the text.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="full-code">Full code</h2>
<p>Below is the full code to create our graph.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;
cls;

/*
** Load and preview data
*/
int_rate = loadd("int_rate.csv");

tail(int_rate);

ks = { 0.517, 0.653, 0.781  };

/*
** Graph data
*/

// Graph size
plotCanvasSize("px", 500 | 400);

// Default settings
struct plotControl plt;
plt = plotGetDefaults("xy");

// Font
plotSetFonts(&amp;plt, "all", "roboto", 14);

// Legend
plotSetLegend(&amp;plt, "", "vcenter left inside", 1);
plotSetLegendBkd(&amp;plt, 0);

// Main line settings
clrs = getColorPalette("set2");
plotSetLinePen(&amp;plt, 4, clrs[3 2], 1|3);

// Axes outline (spine)
plotSetOutlineEnabled(&amp;plt, 1);

// X-axis
plotSetTextInterpreter(&amp;plt, "latex", "xaxis");
plotSetXAxisLabel(&amp;plt, "\\text{country opacity }, \\omega");

// Draw main plot
plotXY(plt, int_rate, "high + low ~ x");

// Style and add vertical lines
plotSetLinePen(&amp;plt, 1, "#CCC", 2);
plotAddVLine(plt, ks);

// Style text boxes
struct plotAnnotation ant;
ant = annotationGetDefaults();
annotationSetTextInterpreter(&amp;ant, "latex");
annotationSetLinePen(&amp;ant, 0, "", -1);
annotationSetFont(&amp;ant, "", 14, "#3333");
annotationSetBkd(&amp;ant, "", 0);

// Add text boxes
plotAddTextbox(ant, "\\omega_1", ks[1], 0.15);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.15);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.15);</code></pre>
<h2 id="bonus-content-text-box-anchor-position">Bonus Content: Text Box Anchor Position</h2>
<p>For this case, we wanted the text boxes to appear to just the right of the vertical lines and the vertical position of the text boxes was not critical. Therefore, the default anchor position worked well.</p>
<p>However, if we had needed the text boxes to be towards the bottom of the graph, the first of them would have overlapped with one of our lines. We can see this by changing the <code>plotAddTextbox</code> lines to the following:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Draw the text boxes at a lower position, y=0.04
plotAddTextbox(ant, "\\omega_1", ks[1], 0.04);
plotAddTextbox(ant, "\\omega_2", ks[2], 0.04);
plotAddTextbox(ant, "\\omega_3", ks[3], 0.04);</code></pre>
<p>This makes the bottom of our graph look like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-overlapping-omega-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-overlapping-omega-1.jpg" alt="" width="499" height="145" class="aligncenter size-full wp-image-11582674" /></a></p>
<p>In this case, it would be nice to move the text boxes to the left of the vertical line. We can do this by using the final optional input of <code>plotAddTextbox</code>. It is a string that allows you to specify the position of the text box with respect to its anchor position.</p>
<p>The string options include:</p>
<ul>
<li><strong>Vertical position</strong>: <code>"top"</code>, <code>"vcenter"</code>, <code>"bottom"</code>.<br/></li>
<li><strong>Horizontal position</strong>: <code>"left"</code>, <code>"hcenter"</code>, <code>"right"</code>.<br/></li>
</ul>
<p>or <code>"center"</code> which is equivalent to <code>"vcenter hcenter"</code>.</p>
<p>For this example, we will just move the text boxes to the left of the vertical lines which are at the same position as the text box's anchor locations:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Draw the text boxes at a lower position, y=0.04
plotAddTextbox(ant, "\\omega_1", ks[1], 0.04, "left");
plotAddTextbox(ant, "\\omega_2", ks[2], 0.04, "left");
plotAddTextbox(ant, "\\omega_3", ks[3], 0.04, "left");</code></pre>
<p>This gives us the following image:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2022/07/gblog-left-omega-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2022/07/gblog-left-omega-1.jpg" alt="" width="496" height="142" class="aligncenter size-full wp-image-11582676" /></a></p>
<h3 id="conclusion">Conclusion</h3>
<p>Great job! You have learned how to:</p>
<ol>
<li>Add and style text boxes with LaTeX.</li>
<li>Set the anchor point of text boxes.</li>
<li>Add and style vertical lines.</li>
<li>Automatically set legend text to use your dataframe's variable names.</li>
<li>Set the font for all or a subset of the graph text elements.</li>
<li>Set the size of your graph.</li>
<li>Control the position of text boxes with respect to their attachment point.</li>
</ol>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/visualizing-covid-19-panel-data-with-gauss-22/" target="_blank" rel="noopener">Visualizing COVID-19 Data with GAUSS 22</a></li>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/" target="_blank" rel="noopener">How to Mix, Match, and Style Different Graph Types</a></li>
<li><a href="https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/" target="_blank" rel="noopener">How to Create Tiled Graphs in GAUSS</a></li>
<li><a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/" target="_blank" rel="noopener">Five Hacks for Creating Custom GAUSS Graphics</a></li>
</ol>
<h3 id="references">References</h3>
<p>Farboodi, Maryam, and Péter Kondor. 2022. &quot;Heterogeneous Global Booms and Busts.&quot; <i>American Economic Review</i>, 112 (7): 2178-2212.
DOI: 10.1257/aer.20181830</p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/advanced-formatting-techniques-for-creating-aer-quality-plots/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>GAUSS 22</title>
		<link>https://www.aptech.com/blog/gauss22/</link>
					<comments>https://www.aptech.com/blog/gauss22/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 16 Nov 2021 19:02:07 +0000</pubDate>
				<category><![CDATA[Releases]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581867</guid>

					<description><![CDATA[GAUSS 22 brings many substantial new features that will save you hours of time and frustration with everyday tasks including:

<ul>
<li>Data exploration</li>
<li>Data cleaning and management</li>
<li>Graphics</li>
</ul>

See some of the ways that GAUSS 22 will help you make the most of your limited research time below!
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>GAUSS 22 brings many substantial new features that will save you hours of time and frustration with everyday tasks like:</p>
<ul>
<li>Data exploration</li>
<li>Data cleaning and management</li>
<li>Graphics</li>
</ul>
<p>See some of the ways that GAUSS 22 will help you make the most of your limited research time below!</p>
<h2 id="intelligent-graph-attributes">Intelligent Graph Attributes</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-crabs-scatter-short-6.gif"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-crabs-scatter-short-6.gif" alt="" width="590" height="405" class=" size-full wp-image-11581879" /></a></p>
<ul>
<li>Specify variables to plot by name with convenient formula strings.</li>
<li>Automatic, intelligent use of variable names and category labels.</li>
<li>Split data using the new 'by' keyword.</li>
<li>Never overwrites your settings.</li>
</ul>
<h2 id="highlight-important-parts-of-your-data">Highlight Important Parts of Your Data</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-usrec-male-female.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-usrec-male-female.jpg" alt="" width="590" height="451" class=" size-full wp-image-11581881" /></a></p>
<ul>
<li>Specify locations with simple date strings, category labels, numbers, or popular datasets.</li>
</ul>
<p><br/></p>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-plotaddhbar-credit-rating.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-plotaddhbar-credit-rating.jpg" alt="" width="590" height="404" class=" size-full wp-image-11581922" /></a></p>
<ul>
<li>Add spanning bars and lines with one line of code.</li>
</ul>
<p><br/></p>
<hr>
<div style="text-align:center">Questions? <a href="https://www.aptech.com/book-an-expert">Book some time</a>  with one of our friendly GAUSS experts</div>
<hr>
<h2 id="simple-data-filtering-with-strings-and-dates">Simple Data Filtering with Strings and Dates</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-selif-covid-vacc.gif"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-selif-covid-vacc.gif" alt="" width="745" height="394" class="size-full wp-image-11581899" /></a></p>
<ul>
<li>Reference dates, category labels, and variable names.</li>
<li>Use greater than and less than comparisons with ordinal data.</li>
</ul>
<h2 id="easily-generate-new-variables">Easily Generate New Variables</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-join-separate-date-vecs.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-join-separate-date-vecs.jpg" alt="" width="522" height="447" class="size-full wp-image-11581903" /></a></p>
<ul>
<li>Create categorical variables from string arrays.</li>
<li>Automatically convert simple date strings to real date variables.</li>
<li>Simple new functions and interactive controls to rename and change types.</li>
<li>Function for combining, splitting, and manipulating strings now support string, categorical and date variables.</li>
</ul>
<hr>
<div style="text-align:center"><a href="https://www.aptech.com/request-demo/">Start your free trial!</a></div>
<hr>
<h2 id="clean-messy-data">Clean Messy Data</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-donor-strclean-2-frames-npup2.gif"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-donor-strclean-2-frames-npup2.gif" alt="" width="605" height="374" class="size-full wp-image-11581929" /></a></p>
<ul>
<li>Fix typos and misentries.</li>
<li>Consolidate categories.</li>
<li>Identify and remove outliers.</li>
<li>Identify and remove duplicate observations.</li>
</ul>
<h2 id="aggregate-by-string-category-or-date">Aggregate by String, Category or Date</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-aggregate-wine-spend.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-aggregate-wine-spend.jpg" alt="" width="528" height="468" class="size-full wp-image-11581907" /></a></p>
<ul>
<li>Options for how to handle missing values.</li>
</ul>
<h2 id="simple-data-merge">Simple Data Merge</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2021/11/g22-outerjoin-2-mark-up.jpg"><img src="https://www.aptech.com/wp-content/uploads/2021/11/g22-outerjoin-2-mark-up.jpg" alt="" width="1622" height="1092" class="size-full wp-image-11581910" /></a></p>
<ul>
<li>Load and combine data from CSV, Excel, SAS, Stata, SPSS.</li>
</ul>
<h3 id="conclusion">Conclusion</h3>
<p>GAUSS 22 has more new features and bug fixes than any previous version. For a complete list of what's new, see the <a href="https://docs.aptech.com/gauss/changelog.html" target="_blank" rel="noopener">changelog</a>.</p>
<div style="text-align:center;background-color:#455560;color:#FFFFFF">
<hr>
<h3 id="discover-how-gauss-22-can-help-you-make-your-mark">Discover how GAUSS 22 can help you make your mark</h3>
 
<div class="lp-cta">
    <a href="https://www.aptech.com/book-an-expert" class="btn btn-primary">Talk with an expert</a>
    <a href="https://www.aptech.com/request-quote/" class="btn btn-primary btn-quote">Request pricing</a>
</div><hr>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/gauss22/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Errors: G0058 Index out-of-Range</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 27 Aug 2021 17:16:16 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[index out-of-range]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581656</guid>

					<description><![CDATA[Today we will help you to understand and resolve <code>Error G0058 Index Out-of-Range</code> We will :
<ol>
<li> Explain the cause of the index out-of-range error in GAUSS.</li>
<li> Explain why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>Show how to use some functions and operators that can assist with diagnosing and resolving this error.</li>
<li> Work through an example to resolve an indexing problem.</li>
</ol>
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today's blog will:</p>
<ol>
<li>Explain the cause of the index out-of-range error in GAUSS.</li>
<li>Explain why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>Show how to use some functions and operators that can assist with diagnosing and resolving this error.</li>
<li>Work through an example to resolve an indexing problem.</li>
</ol>
<h2 id="what-causes-the-index-out-of-range-error">What Causes the Index-out-of-Range Error?</h2>
<p>The index out-of-range error occurs any time that you try to select an element of a <a href="https://www.aptech.com/blog/what-is-a-gauss-dataframe-and-why-should-you-care/" target="_blank" rel="noopener">dataframe</a>, matrix, or string array that does not exist. Let's look at a basic example:</p>
<h3 id="index-out-of-range-on-read">Index out-of-range on read</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create a 2x1 vector
a = { 5, 9 };

// Attempt to access the third element and assign it to 'b'
b = a[3];</code></pre>
<p>In the above example, the error is clear. Since <code>a</code> does not have a third element, trying to access it is clearly an error.</p>
<h3 id="index-out-of-range-on-write">Index out-of-range on write</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create a 2x1 vector
a = { 5, 9 };

// Attempt to assign to the third element of 'a'
a[3] = 12;</code></pre>
<p>Since this code is attempting to write past the end of the vector <code>a</code>, it will also cause an index out-of-range error. This behavior is standard among most programming environments. However, it can sometimes confuse new GAUSS users who are coming from statistical software that has historically been designed more for prototyping.</p>
<p>At first, it might seem convenient for the extra elements to be automatically added past the end of your data. However, there are two reasons why it is not such a good idea:</p>
<ol>
<li><strong>It allows errors to go undetected</strong>. Writing past the end of data is very easy to do by accident and one of the most common errors to make when programming--even for trained professional programmers. Letting the error go undetected at the source can cause a much harder-to-detect error to happen later on in the program. In other cases, <em>it can even lead to wrong answers</em>.</li>
<li><strong>It will slow down your code</strong>. Starting out with a vector, matrix, or dataframe of the correct size and filling it in can be 10 or more times faster than adding new elements an observation at a time.</li>
</ol>
<h2 id="functions-and-operators-to-investigate-and-resolve-an-index-out-of-range-error">Functions and Operators to Investigate and Resolve an Index out-of-range Error</h2>
<p>Here are a few functions and operators that should be helpful when diagnosing and resolving an index out-of-range error.</p>
<table>
<thead>
<tr>
<th>Name</th>
<th>Purpose</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://docs.aptech.com/gauss/cols.html" target="_blank" rel="noopener">cols</a></td>
<td>Returns the number of columns in a dataframe, matrix, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/rows.html" target="_blank" rel="noopener">rows</a></td>
<td>Returns the number of rows in a dataframe, matrix, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/getorders.html" target="_blank" rel="noopener">getorders</a></td>
<td>Returns the size of each dimension in a dataframe, matrix, multi-dimensional array, or string array.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/getorders.html" target="_blank" rel="noopener">zeros</a></td>
<td>Returns a matrix of a specified size filled with zeros. It is often used to pre-allocate a matrix that will be filled in later.</td>
</tr>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Symbol</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>~</td>
<td>Adds columns to a matrix, dataframe, or string array.</td>
</tr>
<tr>
<td>|</td>
<td>Adds rows to a matrix, dataframe, or string array.</td>
</tr>
</tbody>
</table>
<h3 id="basic-usage-examples">Basic Usage Examples</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = { 7 2,
      4 1 };

b = { 5 8,
      3 9 };

c = { 6 6 };

print "rows(a) = " rows(a);
print "cols(a) = " cols(a);
print "----";
print "getorders(a) = " getorders(a);</code></pre>
<p>will return:</p>
<pre>rows(a) =        2.0000000
cols(a) =        2.0000000
----
getorders(a) =
       2.0000000
       2.0000000 </pre>
<p>Continuing with the previous code:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Use horizontal concatenation to add columns
d = a ~ b;

// User vertical concatenation to add rows
e = c | b;</code></pre>
<p>After the above code:</p>
<pre>d = 7 2 5 8
    4 1 3 9

e = 6 6
    5 8
    3 9</pre>
<h2 id="solve-an-example-index-error">Solve an Example Index Error</h2>
<p>Let's work through a simplified real-world example of an out-of-range error. Our code takes some <a href="https://www.aptech.com/blog/basic-bootstrapping-in-gauss/" target="_blank" rel="noopener">bootstrap</a> samples from a dataset and then computes and stores the means and standard deviations of these samples. Here is the initial code:</p>
<pre class="hljs-container hljs-container-solo"><code>burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 1);

for i(1, ndraws + burn_in, 1);
    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>After running the above code, GAUSS reports the index out-of-range error from the line <code>stats[i,2] = stdsc(s);</code>.</p>
<p>Let's start diagnosing this problem by printing out the size of <code>stats</code> before the loop and the value of <code>i</code> on each iteration, like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 1);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>After running this version, we see the following printed output:</p>
<pre>rows(stats) =        10.000000
cols(stats) =        1.0000000
i =        1.0000000 </pre>
<p>This tells us that the error happened on the first iteration of the loop, since <code>i</code> is never greater than one. We also see that <code>stats</code> only has one column. The line causing our error is trying to write to the second column of <code>stats</code>. So we need to add a second column to <code>stats</code> when we pre-initialize it.</p>
<p>After we fix that problem, our code looks like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws, 2);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>Unfortunately, GAUSS is still reporting an index out-of-range error. This time it is on an earlier line, <code>stats[i,1] = meanc(s);</code>. However, when we look at our printed output:</p>
<pre>rows(stats) =        10.000000
cols(stats) =        2.0000000
i =        1.0000000
i =        2.0000000
i =        3.0000000
i =        4.0000000
i =        5.0000000
i =        6.0000000
i =        7.0000000
i =        8.0000000
i =        9.0000000
i =        10.000000
i =        11.000000 </pre>
<p>we see that the code has gotten through several iterations. We can also see that the error occurs when the code tries to write to the 11th row of <code>stats</code>, but <code>stats</code> only has 10 rows. We need to find out why the number of iterations in the loop and the number of rows in <code>stats</code> don't agree.</p>
<p>Looking back over the code, we can see that <code>stats</code> has <code>ndraws</code> rows, but the loop has <code>ndraws</code> + <code>burn_in</code> iterations. There are many ways we could resolve this, but since our main focus is on identifying the cause of the problem, we will just change the size of <code>stats</code> to have enough rows to hold all iterations.</p>
<p>Below is our final code:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">burn_in = 5;
ndraws = 10;

// Data to sample from
data = rndn(10, 1);

// Pre-allocate vector to hold results
stats = zeros(ndraws + burn_in, 2);

print "rows(stats) = " rows(stats);
print "cols(stats) = " cols(stats);

for i(1, ndraws + burn_in, 1);

    print "i = " i;

    // Take a bootstrap sample
    s = sampleData(data, rows(data), 1);

    // Assign the mean of the sample
    // to the 1st column of the i'th row of stats
    stats[i,1] = meanc(s);

    // Assign the standard deviation of the sample
    // to the 2nd column of the i'th row of stats
    stats[i,2] = stdsc(s);

endfor;</code></pre>
<p>Fortunately, this time the code runs without error and the printout shows us that all iterations have been performed--problem solved! We can now remove the print statements and keep going.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! You have learned:</p>
<ol>
<li>The cause of the index out-of-range error in GAUSS.</li>
<li>Why performing index assignments past the end of your data can lead to bad outcomes.</li>
<li>How to use some functions and operators that can assist with finding the size of your data and adding rows and columns.</li>
</ol>
<p>and worked through a simple, but realistic example.</p>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/" target="_blank" rel="noopener">Understanding Errors | G0025 : Undefined symbol</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/" target="_blank" rel="noopener">Understanding Errors: G0064 Operand Missing</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Errors: G0064 Operand Missing</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Mon, 26 Jul 2021 14:26:38 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[operand]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581524</guid>

					<description><![CDATA[Today we will help you to understand and resolve Error G0064: Operand Missing. We will answer the questions:

<ol>
<li>What is an operand?</li>
<li> How do common mathematical and non-mathematical operators interact with operands?</li>
<li>What are common causes of operand missing errors?</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today we will help you to understand and resolve <code>Error G0064: Operand Missing</code>. We will answer the questions:</p>
<ul>
<li>What is an operand?</li>
<li>How do common mathematical and non-mathematical operators interact with operands?</li>
<li>What are common causes of operand missing errors?</li>
</ul>
<h2 id="what-is-an-operand">What is an operand?</h2>
<p>An operand is a symbol that an operator operates on. For example, in the line below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">X = 4 + 5;</code></pre>
<p>The plus sign is the operator and both <code>4</code> and <code>5</code> are operands.</p>
<h2 id="mathematical-and-logical-operators">Mathematical and Logical Operators</h2>
<p>When you think of operators, the mathematical and logical operators tend to come to mind first. For example, operators like those shown in the table below.</p>
<table>
 <thead>
 <tr>
      <th style="background-color: #36434C" colspan="3"><span style="color:#FFFFFF">Mathematical and Logical Operators</span>
      </th>
   </tr>
<tr><th>Operator</th><th>Purpose</th>
</tr></thead>
<tbody>
<tr><td><code>+</code></td><td>Addition.</td></tr>
<tr><td><code>*</code>, <code>.*</code></td><td>Multiplication and element-by-element multiplication.</td></tr>
<tr><td><code>^</code></td><td>Exponentiation.</td></tr>
<tr><td><code>==</code>, <code>.==</code></td><td>Logical equality and element-by-element logical equality.</td></tr>
<tr><td><code>!==</code>, <code>.!==</code></td><td>Logical not equal and element-by-element logical not equal
</td></tr><tr><td><code>&gt;</code>, <code>.&gt;</code></td><td>Greater than and element-by-element greater.</td></tr>
</tbody>
</table>
<h3 id="operand-missing-errors-with-mathematical-and-logical-operators">Operand Missing Errors with Mathematical and Logical Operators</h3>
<p>Missing operand errors that occur with mathematical operators tend to be simple to understand and fix, so we will only show one example.</p>
<p><strong>Example 1</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Multiply 6 by 5 
// and print  
// the result
6.*5;</code></pre></td><td><pre><code>// The left-hand 
// operand is 
// missing
.*5;</code></pre></td></tr>
<tr><td>The element-by-element multiplication operator requires two operands, one on the right-hand side and one on the left.</td><td>The code snippet is missing the left side operand and will return the operand missing error.</td></tr>
</tbody>
</table>
<h2 id="non-mathematical-operators">Non-mathematical Operators</h2>
<p>Unlike the logical and mathematical operators, many of the “other” operators are not commonly noticed or considered.</p>
<table>
 <thead>
 <tr>
      <th style="background-color: #36434C" colspan="3"><span style="color:#FFFFFF">Non-mathematical Operators</span>
      </th>
   </tr>
<tr><th>Operator</th><th>Description</th><th>Purpose</th>
</tr></thead>
<tbody>
<tr><td><code>,</code></td><td>Commma</td><td>Separates items in lists.</td></tr>
<tr><td><code> </code></td><td>Space</td><td>Separates items in print statements and indices inside index brackets.</td></tr>
<tr><td><code>.</code></td><td>Period</td><td>Signifies all rows or all columns inside of index brackets.</td></tr>
<tr><td><code>:</code></td><td>Colon</td><td>Creates a continuous series of indices inside of index brackets.</td></tr></tbody>
</table>
<h3 id="comma-operator-examples">Comma Operator Examples</h3>
<p><strong>Comma Operator Example One</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Create a 4x2 matrix with 
// random normally 
// distributed numbers
X = rndn(4,2);</code></pre></td><td><pre><code>// No operands on either 
// side of the comma 
// operator
X = rndn(,);</code></pre></td></tr>
<tr><td>The comma operator is used to separate the operands 4 and 2.</td><td>The comma operator is used, but there are no operands for the comma operator to separate. </td></tr>
</tbody>
</table>
<p><strong>Comma Operator Example Two</strong></p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Assign the element from  
// the 6th row and first 
// column to Z
Z = X[6,1];</code></pre></td><td><pre><code>// The operand to the right 
// of the comma operator 
// is missing
Z = X[6, ];</code></pre></td></tr>
<tr><td>The comma operator separates the index operands 6 and 1.</td><td>The comma operator is used, but there is not a column index on the right side of the comma.</td></tr>
</tbody>
</table>
<h3 id="colon-operator-example">Colon Operator Example</h3>
<p>Operand missing statements with the colon operator will look like the previous comma operator errors. </p>
<table>
<thead>
<tr><th style="background-color: #E5F2E5"><span style="color:#008000">Correct statement</span></th><th style="background-color: #ffe5e5"><span style="color:#FF0000">Incorrect statement</span></th></tr>
</thead>
<tbody>
<tr><td><pre><code>// Assign the 3rd to 5th 
// elements from the vector
// y to u
u = y[3:5];</code></pre></td><td><pre><code>// The operand to the
// right of the colon 
// operator is missing
u = y[3: ];</code></pre></td></tr>
<tr><td>The colon operator separates the index operands 3 and 5.</td><td>The colon operator is used, but there is not a column index on the right side of the colon.</td></tr>
</tbody>
</table>
<h2 id="print-statements-and-the-space-operator">Print Statements and the Space Operator</h2>
<p>The usage of space operator is probably the most likely “operand missing” error to trip up new GAUSS users.</p>
<p>The <a href="https://docs.aptech.com/gauss/print.html" target="_blank" rel="noopener"><code>print</code></a> statement takes a space-separated list of items to print. For example:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">print 4 5 6;</code></pre>
<p>will return:</p>
<pre>4.0000    5.0000    6.0000</pre>
<p>Similarly, we can print the same data with variables like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">A = 4;
B = 5;

print A B 6;</code></pre>
<p>And GAUSS will again return:</p>
<pre>4.0000    5.0000    6.0000</pre>
<p>So far this is quite simple and something you may have done without a thought. However, adding an operator can cause a problem. For example, because the <code>print</code> statement uses the space operator to separate the items to print, the statement:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">print A + B;</code></pre>
<p>is interpreted by GAUSS as the following instructions:</p>
<p>Print the value of A.<br />
Print the value of +.<br />
Print the value of B.    </p>
<p>Therefore, when GAUSS gets to the <code>+</code> sign, it does not see enough operands, because it has already been told to print A.</p>
<p>You can resolve this by removing the space operator between <code>A</code>, <code>+</code> and <code>B</code>, or by adding parentheses around the statement.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">A = 4;
B = 5;

// Option 1: Add parentheses 
// around the sum of A and B
print (A + B);

// Option 2: Remove space operator 
// to print the sum of A and B
print A+B;</code></pre>
<p>The parentheses (or dropped spaces) only need to be around the operator. The table below shows a few variations and the resulting printed output.</p>
<table>
 <thead>
<tr><th>Statement</th><th>Output</th></tr>
</thead>
<tbody>
<tr><td><pre><code>print (4 + 5) 6;</code></pre></td><td><code>9.0000    6.0000</code></td></tr>
<tr><td><pre><code>print (4 + 5)*6;</code></pre></td><td><code>54.0000</code></td></tr>
<tr><td><pre><code>print  ((4 + 5) / 6);</code></pre></td><td><code>1.5000</code></td></tr>
<tr><td><pre><code>print 4 5*6;</code></pre></td><td><code>4.0000 30.0000</code></td></tr>
</tbody></table>
<h3 id="conclusion">Conclusion</h3>
<p>Congratulations! In today's blog, you have learned:</p>
<ul>
<li>What mathematical, logical, and non-mathematical operands are in GAUSS. </li>
<li>Common causes of the <code>G0064: Operand Missing</code> error.</li>
</ul>
<h3 id="further-reading">Further reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/" target="_blank" rel="noopener">Understanding Errors | G0025 : Undefined symbol</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/" target="_blank" rel="noopener">Understanding Errors: G0058 Index out-of-Range</a></li>
<li><a href="https://www.aptech.com/blog/gauss-basics-6-logical-and-relational-operators/" target="_blank" rel="noopener">GAUSS Basics 6: Logical and relational operators</a></li>
</ol>
<p>    <!-- MathJax configuration -->
    <style>
        .mjx-svg-href {
            fill: "inherit" !important;
            stroke: "inherit" !important;
        }
    </style>
    <script type="text/x-mathjax-config">
        MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "AMS"} } });
    </script>
    <script type="text/javascript">
window.MathJax = {
  tex2jax: {
    inlineMath: [ ['$','$'] ],
    displayMath: [ ['$$','$$'] ],
    processEscapes: true,
    processEnvironments: true
  },
  // Center justify equations in code and markdown cells. Elsewhere
  // we use CSS to left justify single line equations in code cells.
  displayAlign: 'center',
  "HTML-CSS": {
    styles: {'.MathJax_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  "SVG": {
    styles: {'.MathJax_SVG_Display': {"margin": 0}},
    linebreaks: { automatic: false }
  },
  showProcessingMessages: false,
  messageStyle: "none",
  menuSettings: { zoom: "Click" },
  AuthorInit: function() {
    MathJax.Hub.Register.StartupHook("End", function() {
            var timeout = false, // holder for timeout id
            delay = 250; // delay after event is "complete" to run callback
            var shrinkMath = function() {
              //var dispFormulas = document.getElementsByClassName("formula");
              var dispFormulas = document.getElementsByClassName("MathJax_SVG_Display");
              if (dispFormulas){
                // caculate relative size of indentation
                var contentTest = document.getElementsByTagName("body")[0];
                var nodesWidth = contentTest.offsetWidth;
                // if you have indentation
                var mathIndent = MathJax.Hub.config.displayIndent; //assuming px's
                var mathIndentValue = mathIndent.substring(0,mathIndent.length - 2);
                for (var i=0; i<dispFormulas.length; i++){
                  var dispFormula = dispFormulas[i];
                  var wrapper = dispFormula;
                  //var wrapper = dispFormula.getElementsByClassName("MathJax_Preview")[0].nextSibling;
                  var child = wrapper.firstChild;
                  wrapper.style.transformOrigin = "center"; //or top-left if you left-align your equations
                  var oldScale = child.style.transform;
                  //var newValue = Math.min(0.80*dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newValue = Math.min(dispFormula.offsetWidth / child.offsetWidth,1.0).toFixed(2);
                  var newScale = "scale(" + newValue + ")";
                  if(newValue != "NaN" && !(newScale === oldScale)){
                    wrapper.style.transform = newScale;
                    wrapper.style["margin-left"]= Math.pow(newValue,4)*mathIndentValue + "px";
                    var wrapperStyle = window.getComputedStyle(wrapper);
                    var wrapperHeight = parseFloat(wrapperStyle.height);
                    wrapper.style.height = "" + (wrapperHeight * newValue) + "px";
                    if(newValue === "1.00"){
                      wrapper.style.cursor = "";
                      wrapper.style.height = "";
                    }
                    else {
                      wrapper.style.cursor = "zoom-in";
                    }
                  }

                }
            }
            };
            shrinkMath();
            window.addEventListener('resize', function() {
              clearTimeout(timeout);
              timeout = setTimeout(shrinkMath, delay);
            });
          });
  }
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-AMS_SVG"></script></p>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Errors &#124; G0025 : Undefined symbol</title>
		<link>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/</link>
					<comments>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 23 Apr 2021 18:21:41 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[undefined symbol]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11581214</guid>

					<description><![CDATA[Today we will help you to understand and resolve <code>Error G0025: Undefined symbol</code> We will answer the questions:
<ol>
<li> What is a GAUSS symbol</li>
<li> What are the most common types of GAUSS symbols?</li>
<li>How do I define a GAUSS symbol?</li>
<li> How do I resolve the error `G0025: Undefined symbol`?</li>
</ol>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Today we will help you to understand and resolve <code>Error G0025: Undefined symbol</code>. We will answer the questions:</p>
<ul>
<li>What is a GAUSS symbol?</li>
<li>What are the most common types of GAUSS symbols?</li>
<li>How do I define a GAUSS symbol?</li>
<li>How do I resolve the error <code>G0025: Undefined symbol</code>?</li>
</ul>
<h2 id="what-is-a-symbol">What is a symbol?</h2>
<p>In GAUSS a symbol is a label used to represent some data, a procedure or function. For example, in the code below:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a = 3;
b = 4;</code></pre>
<p><code>a</code> and <code>b</code> are symbols representing the scalar values 3 and 4 respectively.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">c = a + b;

d = 3 + 4;</code></pre>
<p>The above code creates two new symbols, <code>c</code> and <code>d</code>.</p>
<ul>
<li><code>c</code> is created by applying the addition operator to the previously created symbols, <code>a</code> and <code>b</code>. </li>
<li><code>d</code> is created by adding two literal values. </li>
</ul>
<p>Numbers, such as the integers <code>3</code> and <code>4</code> are called <em>literals</em>, rather than <em>symbols</em>.</p>
<h2 id="how-to-define-a-symbol">How to define a symbol</h2>
<p><strong>Numeric and string symbols</strong> are defined in GAUSS using the equals sign as we saw previously. Here are some more examples:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Define the symbol 'e' to be a 3x1 vector
e = { 2.1, 0.9, 3.8 };

// Define the symbol 'f' to be the
// largest element of the vector 'e'
f = maxc(e);

// Define the symbol 'g' to be a 10x2 random normal matrix
g = rndn(10,2);

// Define the symbol 'h' to be a string
h = "String symbols contain text";</code></pre>
<p><strong>Procedure (<code>proc</code>) and function (<code>fn</code>) names</strong> are also symbols. Below are some simple examples of procedure definitions:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">/*
** The procedure and function definitions below define the symbols
** 'doubleIt' and 'squareIt'.
*/

proc (1) = doubleIt(X);
    retp(X .* 2);
endp;

fn squareIt(X) = X .^ 2;</code></pre>
<div class="alert alert-info" role="alert">Read more about <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/" target="_blank" rel="noopener">creating GAUSS procedures</a> in this blog post.</div>
<h2 id="basic-undefined-symbol-examples">Basic undefined symbol examples</h2>
<p>Any time a symbol is referenced on the right side of an equation before it has been defined can cause <code>Error G00025: Undefined symbol</code>. Here are a few simple examples:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

// Since 'a' has not been defined,
// this line will cause an error
b = a;</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

b = 3;

// Since 'a' has not been defined,
// this line will cause an error
c = a + b;</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear out all symbols in the GAUSS workspace
new;

a = { 2, 4, 6 };

// Since the procedure 'foo' has not been defined,
// this line will cause an error
X = foo(a);</code></pre>
<h2 id="solve-a-simple-undefined-symbols-error">Solve a simple undefined symbols error</h2>
<p>If we run a file named <code>estimate.gss</code> with the following contents:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from the GAUSS workspace
new;

/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);

/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);

/*
** Estimate a linear model
*/
call glm(y, X, "normal");</code></pre>
<p>we will get the following error messages:</p>
<pre>G0025 : Undefined symbol: 'nobs'  [estimate.gss, line 6]
G0025 : Undefined symbol: 'nvars' [estimate.gss, line 6]</pre>
<p>These error messages tell us that line 6 of our code is using two symbols that have not yet been defined, <code>nobs</code> and <code>nvars</code>. To resolve these errors, we need to set those symbols to appropriate values.</p>
<p>The inputs to the <a href="https://docs.aptech.com/gauss/rndn.html" target="_blank" rel="noopener"><code>rndn</code></a> function need to be scalar values that represent the number of rows and columns of the output matrix. We set them to 100 and 4 respectively in the code below to resolve the errors.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from the GAUSS workspace
new;

// Specify the number of observations to simulate
nobs = 100;

// Specify the number of columns to simulate
nvars = 4;

/*
** Simulate random normal variables
*/
X = rndn(nobs, nvars);

/*
** Simulate a random normal response variable
*/
y = rndn(nobs, 1);

/*
** Estimate a linear model
*/
call glm(y, X, "normal");</code></pre>
<p>After these changes the code will run successfully.</p>
<h2 id="what-causes-undefined-proc-or-function-symbols">What causes undefined proc or function symbols?</h2>
<p>Now let's move to a less obvious example. Let's suppose we have a file <code>arimafit-example.gss</code> with these contents:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all symbols from GAUSS workspace
new;

// Create file name with full path
fname = getGAUSSHome() $+ "pkgs/tsmt/examples/enders_sim2.dat";

p = 3;
d = 1;
q = 1;

// Run arima estimation
call arimaFit(fname, "ar2", p, d, q);</code></pre>
<p>When we run this file, we get the error:</p>
<pre>G0025 : Undefined symbol: 'arimaFit' [arimafit-example.gss, line 12]</pre>
<p>In this example, we can tell that <code>arimaFit</code> is a GAUSS procedure or function. There are four main reasons why a procedure or function might be undefined in your GAUSS code:</p>
<h3 id="1-it-was-added-in-a-newer-version-of-gauss-than-you-have">1. It was added in a newer version of GAUSS than you have.</h3>
<p>You can search the <a href="https://docs.aptech.com/gauss/changelog.html" target="_blank" rel="noopener">GAUSS Change Log</a> for the procedure or function to see if it has been added in a newer version.</p>
<h3 id="2-it-is-in-a-library-that-you-do-not-have-loaded">2. It is in a library that you do not have loaded.</h3>
<p><a href="https://docs.aptech.com/gauss/tsmt/arimafit.html" target="_blank" rel="noopener"><code>arimaFit</code></a> from our above code snippet is from the <a href="https://docs.aptech.com/gauss/tsmt/index.html" target="_blank" rel="noopener">GAUSS Time Series MT</a> add-on package. If this is the case, you will need to <a href="https://www.aptech.com/blog/using-gauss-packages-complete-guide/" target="_blank" rel="noopener">make sure that the package is installed and loaded</a> correctly.</p>
<p>Undefined references to the procedures <code>maxset</code>, <code>optset</code>, <code>maxlik</code> and <code>optmum</code> are sometimes found undefined in publicly available third-party code.</p>
<h3 id="3-it-is-in-a-code-file-that-gauss-has-not-been-told-about">3. It is in a code file that GAUSS has not been told about.</h3>
<p><a href="https://www.aptech.com/blog/basics-of-gauss-procedures/#define_procs" target="_blank" rel="noopener">Our Basics of GAUSS Procedures blog</a> explains the four ways to tell GAUSS about your user-defined procedure. </p>
<div class="alert alert-info" role="alert">The symbol named could also be misspelled, but the <a href="https://www.aptech.com/blog/controlling-the-gauss-autocomplete-behavior/" target="_blank" rel="noopener">GAUSS autocomplete</a> should help prevent that.</div>
<h3 id="4-running-the-code-line-by-line">4. Running the code line-by-line</h3>
<p>When you run a file all at once, GAUSS allows you to place procedures wherever you like, such as the end of the file.</p>
<pre class="hljs-container hljs-container-solo"><code>new;

a = 3;

b = doubleIt(a);

proc (1) = doubleIt(x);
    retp(2 * x);
endp;</code></pre>
<p>However, if you run a program file like the one above, line-by-line, you will get an undefined symbol error. If you run the entire file at once, GAUSS will search the file for any procedures that it does not know about. However, when you run the code line-by-line, GAUSS only runs the code you tell it to run.</p>
<p>You can resolve this problem, by either:</p>
<ol>
<li>Running the code under the debugger.</li>
<li>Adding the procedures to a GAUSS library or <a href="https://www.aptech.com/blog/basics-of-gauss-procedures/#dot_g_proc_file" target="_blank" rel="noopener">a <code>.g</code> file</a>.</li>
<li>Highlighting all lines of the needed procedures and running them first.</li>
</ol>
<h2 id="conclusion">Conclusion</h2>
<p>Congratulations! In today's blog, you have learned that:</p>
<ul>
<li>GAUSS symbols are labels, or names, that represent data, procedures and functions.</li>
<li>Use of a symbol on the right side of an equation before it is defined, or assigned a value, can cause an undefined symbol error.</li>
<li>Symbols are commonly defined by using the equals operator as well as loading libraries.</li>
</ul>
<h3 id="further-reading">Further Reading</h3>
<ol>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0064-operand-missing/" target="_blank" rel="noopener">Understanding Errors: G0064 Operand Missing</a></li>
<li><a href="https://www.aptech.com/blog/understanding-errors-g0058-index-out-of-range/" target="_blank" rel="noopener">Understanding Errors: G0058 Index out-of-Range</a></li>
<li><a href="https://www.aptech.com/blog/make-your-code-portable-data-paths/" target="_blank" rel="noopener">Make your code portable: Data paths</a></li>
<li><a href="https://www.aptech.com/blog/the-current-working-directory-what-you-need-to-know/" target="_blank" rel="noopener">The Current Working Directory: What you need to know</a></li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/understanding-errors-g0025-undefined-symbol/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Easy and Fast Data Management in GAUSS 21</title>
		<link>https://www.aptech.com/blog/easy-and-fast-data-management-in-gauss-21/</link>
					<comments>https://www.aptech.com/blog/easy-and-fast-data-management-in-gauss-21/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 08 Dec 2020 18:45:41 +0000</pubDate>
				<category><![CDATA[Releases]]></category>
		<category><![CDATA[Video]]></category>
		<category><![CDATA[data management]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=11580224</guid>

					<description><![CDATA[The new dataframes and interactive data management tools in GAUSS 21 will make your work more enjoyable and save you hours of time. Learn more about the latest features including:
<ul>
<li>New dataframes that handle strings, categories, and dates with ease.</li>
<li>Interactive data filtering.</li>
<li>Easy to manage date displays.</li>
<li>Interactive management of categorial variables.</li>
<li>Auto-generated code.</li>
</ul>]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>The new dataframes and interactive data management in GAUSS 21 will make your work more enjoyable and <strong>save you hours of time</strong>.</p>
<h2 id="new-gauss-dataframes-make-data-easy-to-read">New GAUSS dataframes make data easy to read...</h2>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/12/g21-dateframe-close-up-thin-orange0.png"><img src="https://www.aptech.com/wp-content/uploads/2020/12/g21-dateframe-close-up-thin-orange0.png" alt="" width="1171" height="774" class="aligncenter size-full wp-image-11580364" /></a></p>
<h3 id="and-make-code-and-results-clearer">...and make code and results clearer</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">&gt;&gt; // Load data
&gt;&gt; lending = loadd("lending.csv");
&gt;&gt;
&gt;&gt; // Estimate in one line
&gt;&gt; call olsmt(lending, "int_rate ~ .");

                                            Std.           
Variable                     Estimate      Error   t-value 
-----------------------------------------------------------

CONSTANT                       11.988     1.298      9.235 
term: 60_months                 3.987    0.6446      6.184 
annual_inc                 -0.0092475  0.005473     -1.689 
purpose: credit_card         -0.12827     1.320   -0.09714 
         renewable_energy     -1.9637     4.229    -0.4643 
         small_business        3.9262     1.799      2.182 
         vacation             -0.7038     1.809    -0.3890</code></pre>
<hr>
<div style="text-align:center">Questions? <a href="https://www.aptech.com/contact-us">Get an answer from our experts</a> or <a href="https://www.aptech.com/request-quote/">request a quote!</a></div>
<hr>
<h3 id="customize-your-date-display">Customize your date display</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/12/g21-date-close-up-thin-green0.png"><img src="https://www.aptech.com/wp-content/uploads/2020/12/g21-date-close-up-thin-green0.png" alt="" width="2366" height="1352" class="aligncenter size-full wp-image-11580362" /></a></p>
<h3 id="reference-your-data-by-name">Reference your data by name</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Index by variable name
auto = auto[., "mpg" "rep78"];

// Select if position is center
nba = selif(nba, nba[., "Pos"] .$== "C");

// Set base category
yarn = setBaseCat(yarn, "low","yarn_length");</code></pre>
<h3 id="see-your-data-your-way-with-gauss-dataframes">See your data your way with GAUSS dataframes</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">&gt;&gt; print lending[1:5,.];</code></pre>
<pre>        int_rate             date          purpose
       12.620000       2014-12-14      credit_card
       9.4400000       2014-05-18             auto
       10.420000       2014-02-01          medical
       15.050000       2014-04-05      credit_card
       9.9300000       2014-05-17      credit_card </pre>
<style>.container .col { padding: 7px; } ul.push-top li { margin-top: 0px; }</style>
<div class="container">
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Missing value support.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Simpler data cleaning.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Categorical, date, string and numeric data.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Clear data view and reporting.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Reference by name or traditional matrix indexing.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Compatible with matrices and older code and application modules.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Programmatic and interactive support:
<ul class="push-top"><li>Category base case, labels and order.</li><li>Date display format.</li></ul>
</div>
  </div>
</div>

<div id="video"></div>
<iframe width="560" height="315" style="display:block" class="aligncenter" src="https://www.youtube.com/embed/jhLP_iJeheA" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

<div id="interactive"></div>
<h2 id="easy-and-fast-interactive-data-management">Easy and fast interactive data management</h2>
<h3 id="interactive-data-import">Interactive data import</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/12/gauss21-interactive-filter-lending-20.png"><img src="https://www.aptech.com/wp-content/uploads/2020/12/gauss21-interactive-filter-lending-20.png" alt="" width="1618" height="762" class="aligncenter size-full wp-image-11580395" /></a></p>
<div class="container">
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> One-click import and preview.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Select and rename variables.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> CSV, Excel, SAS, Stata, SPSS files.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Live preview.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Automatic code generation.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Manage categories.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Specify values to import as missing.</div>
  </div>
</div>
<p><br/></p>
<h3 id="view-rename-and-reorder-categorical-variables">View, rename, and reorder categorical variables</h3>
<div class="container">
  <div class="row">
    <div class="col"><img src="/wp-content/uploads/2020/12/category.svg" width="128" height="128" class="aligncenter"></div>
    <div class="col">Intuitive interactive controls to:
      <ul>
        <li>Set the base case.</li>
        <li>Rename labels.</li>
        <li>Set category order.</li>
      </ul>
    </div>
  </div>
</div>
<h3 id="import-dates-in-any-format">Import dates in any format</h3>
<div class="container">
  <div class="row">
    <div class="col"><img src="/wp-content/uploads/2020/12/calendar.svg" width="128" height="128" class="aligncenter"></div>
    <div class="col">Non-standard date formats are no problem.
      <ul>
        <li>Auto-detects 30 formats.</li>
        <li>Specify any custom format.</li>
        <li>Any characters.</li>
        <li>Any order.</li>
      </ul>
    </div>
  </div>
</div>
<hr>
<div style="text-align:center"><a href="https://www.aptech.com/request-demo/" < a>Request a free trial!</a></div>
<hr>
<h3 id="interactive-data-filter">Interactive data filter</h3>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/12/g21-filter-interactive-chop0-1.png"><img src="https://www.aptech.com/wp-content/uploads/2020/12/g21-filter-interactive-chop0-1.png" alt="" width="1624" height="650" class="aligncenter size-full wp-image-11580350" /></a></p>
<div class="container">
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Simple dropdown options.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Handles missing data.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Create multiple filters.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Live preview.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Automatic code generation.</div>
    <div class="col"><span style="color:#ec7e1d">✔</span> Intuitive date filtering.</div>
  </div>
  <div class="row">
    <div class="col"><span style="color:#ec7e1d">✔</span> Available for data before and after loading.</div>
  </div>
</div>
<div style="text-align:center;background-color:#455560;color:#FFFFFF">
<hr>
<h3 id="find-out-how-much-time-gauss-21-can-save-you">Find out how much time GAUSS 21 can save you!</h3>
 
<div class="lp-cta">
    <a href="https://www.aptech.com/contact-us" class="btn btn-primary">Ask a question</a>
    <a href="https://www.aptech.com/request-quote/" class="btn btn-primary btn-quote">Request pricing</a>
</div><hr>
</div>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/easy-and-fast-data-management-in-gauss-21/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Create Tiled Graphs in GAUSS</title>
		<link>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/</link>
					<comments>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/#respond</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Tue, 04 Aug 2020 17:07:24 +0000</pubDate>
				<category><![CDATA[Graphics]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=22489</guid>

					<description><![CDATA[Placing graphs next to each other can be a great way to present information and improve data visualization. Today we will learn how to create tiled graphs in GAUSS with the easy-to-use <a href="https://docs.aptech.com/gauss/plotlayout.html">plotLayout</a> procedure. <br>
<br>
We will work through two simple examples where you will learn:
<ul>
<li>How to created tiled layouts which are uniform and layouts with graphs of different sizes.</li>
<li>Which graph types can be used with <strong>plotLayout</strong>.</li>
<li>How to clear your tiled graph layouts.</li>
</ul>
]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Placing graphs next to each other can be a great way to present information. Today we will learn how to create tiled graphs in GAUSS using <a href="https://docs.aptech.com/gauss/plotlayout.html"><code>plotLayout</code></a>. </p>
<p>We will work through two simple examples where you will learn:</p>
<ul>
<li>How to created tiled layouts which are uniform and layouts with graphs of different sizes.</li>
<li>Which graph types can be used with <code>plotLayout</code>.</li>
<li>How to clear your tiled graph layouts.</li>
</ul>
<h2 id="how-to-use-plotlayout">How to use plotLayout</h2>
<p>In GAUSS, <code>plotLayout</code> allows you to arrange multiple graphs in a tiled layout. It takes the following inputs:</p>
<hr>
<dl>
<dt>g_rows</dt>
<dd>The number of rows in the graph grid.</dd>
<dt>g_cols</dt>
<dd>The number of columns in the graph grid.</dd>
<dt>idx</dt>
<dd>The cell in which to place the next graph, walking along the rows.
<hr></dd>
</dl>
<p>Therefore, the call:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">plotLayout(2, 3, idx);</code></pre>
<p>will:</p>
<ol>
<li>Split the graph canvas into a 2x3 grid. </li>
<li>Place the next graph in the cell corresponding to the value of <code>idx</code> as shown below.</li>
</ol>
<div>
<table>
<tr height="100 px"><td>idx = 1</td><td>idx = 2</td><td>idx = 3</td></tr>
<tr height="100 px"><td>idx = 4</td><td>idx = 5</td><td>idx = 6</td></tr>
</table>
</div>
<div class="alert alert-info" role="alert"><strong>Note</strong>: <code>plotLayout</code> does not actually alter the graph canvas. It computes and stores the coordinates needed to place your graph tile.</div>
<h2 id="which-graph-types-can-be-used-with-plotlayout">Which Graph Types Can be Used with plotLayout?</h2>
<p>Below is a partial list of the GAUSS graph functions which can be used with <code>plotLayout</code>. Each cell is independent and may contain a different graph type.</p>
<table>
<thead>
<tr>
<th>Function</th>
<th>Graph type</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotxy.html">plotXY</a></td>
<td>XY line.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotscatter.html">plotScatter</a></td>
<td>2-D Scatter.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotts.html">plotTS</a></td>
<td>Time series line.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plottshf.html">plotTSHF</a></td>
<td>High frequency and irregular time series lines.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotbar.html">plotBar</a></td>
<td>2-D bars.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotbox.html">plotBox</a></td>
<td>Box plots.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plothist.html">plotHist</a>, <a href="https://docs.aptech.com/gauss/plothistp.html">plotHistP</a></td>
<td>Standard and percentage histograms.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotlogx.html">plotLogX</a>, <a href="https://docs.aptech.com/gauss/plotlogy.html">plotLogY</a>, <a href="https://docs.aptech.com/gauss/plotloglog.html">plotLogLog</a></td>
<td>Line plot where one or more of the axes are in log space.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotcontour.html">plotContour</a></td>
<td>Contours.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotarea.html">plotArea</a></td>
<td>Stacked area.</td>
</tr>
<tr>
<td><a href="https://docs.aptech.com/gauss/plotxyfill.html">plotXYFill</a></td>
<td>Area between two vectors.</td>
</tr>
</tbody>
</table>
<h2 id="example-1-uniform-grid-layout">Example 1: Uniform Grid Layout</h2>
<p>Now that we have seen the basics of <code>plotLayout</code>, let's put together a simple example placing 4 graphs in a 2x2 grid.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Create the vector 0.1, 0.2, 0.3...3.0
x = seqa(0.1, 0.1, 30);

/*
** First subplot
*/

// Divide the graph canvas into a 2x2 grid
// and place the next graph in the 1st cell
plotLayout(2, 2, 1);

// Create 'y1' and draw graph
y1 = exp(x);
plotXY(x, y1);

/*
** Second subplot
*/
plotLayout(2, 2, 2);

y2 = sin(x);
plotXY(x, y2);

/*
** Third subplot
*/
plotLayout(2, 2, 3);

y3 = cos(x);
plotXY(x, y3);

/*
** Fourth subplot
*/
plotLayout(2, 2, 4);

y4 = ln(x);
plotXY(x, y4);</code></pre>
<p>After running the above code, you should see a graph that looks like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-1.jpg" alt="Simple GAUSS tiled graph." width="600" height="450" class="aligncenter size-full wp-image-22523" /></a></p>
<h3 id="clearing-the-plot-layout">Clearing the Plot Layout</h3>
<p>What do you think would happen if we created another plot right after running the code from the previous section? Let's try it with the code below.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create new 'y' by adding uniform random
// numbers to the 'x' created above
y = x + rndu(30,1);

// Draw graph
plotScatter(x, y);</code></pre>
<p>This time your graph should look like this:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-2x2-2.jpg" alt="Subplots in GAUSS." width="600" height="450" class="aligncenter size-full wp-image-22528" /></a></p>
<p>As we can see, GAUSS remembers the grid we created with our last call to <code>plotLayout</code> as well as the chosen cell index. This state will persist until one of the following statements has been executed:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Subsequent graphs will fill the entire graph canvas.
plotClearLayout();</code></pre>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// 1. Clear all data from the GAUSS workspace.
// 2. Clear the current plot layout state, so that new graphs will fill the entire graph canvas.
new;</code></pre>
<h2 id="example-2-mixed-size-grid-layout">Example 2: Mixed Size Grid Layout</h2>
<p>Sometimes your graphs will look better with tiles of different sizes. Fortunately, as we saw earlier, <code>plotLayout</code> only computes and stores coordinates.</p>
<p>Therefore, each call to <code>plotLayout</code> is independent of any previous calls. As long as your graph tiles do not overlap, each call to <code>plotLayout</code> may use a different grid size. This allows you to mix graphs of different sizes in the same graph canvas. </p>
<p>Let's modify our previous example, so that the third graph takes up the entire second row.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">new;

// Create the vector 0.1, 0.2, 0.3...3.0
x = seqa(0.1, 0.1, 30);

/*
** First subplot
*/

// Divide the graph canvas into a 2x2 grid
// and place the next graph in the 1st cell
plotLayout(2, 2, 1);

// Create 'y1' and draw graph
y1 = exp(x);
plotXY(x, y1);

/*
** Second subplot
*/
plotLayout(2, 2, 2);

y2 = sin(x);
plotXY(x, y2);

/*
** Third subplot
**
**     Change to interpret the graph canvas
**     as a 2x1 grid and place the next graph
**     in the second cell.
*/
plotLayout(2, 1, 2);

y3 = cos(x);
plotXY(x, y3);</code></pre>
<p>In this code example, we changed the inputs to <code>plotLayout</code> instructing it to:</p>
<ul>
<li>Split the graph canvas into a grid with 2 rows and 1 column.</li>
<li>Place the next graph in the second cell.</li>
</ul>
<p>This results in the graph below with the third plot taking up the entire second row of the graph canvas.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-mixed-1.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/08/gblog-plotlayout-mixed-1.jpg" alt="Tiled GAUSS graphs of different sizes." width="600" height="450" class="aligncenter size-full wp-image-22535" /></a></p>
<h3 id="conclusion">Conclusion</h3>
<p>Congratulations, you now have another tool in your graph creating toolbox! You have learned how to: </p>
<ol>
<li>Create tiled graphics in GAUSS.</li>
<li>Create uniform and mixed size layouts.</li>
<li>Clear the plot layout grid.</li>
</ol>
<h3 id="next-steps">Next Steps</h3>
<ul>
<li><a href="https://www.aptech.com/blog/how-to-mix-match-and-style-different-graph-types/">How to Mix, Match and Style Different Graph Types.</a></li>
<li><a href="https://www.aptech.com/blog/five-hacks-for-creating-custom-gauss-graphics/">Five Hacks For Creating Custom GAUSS Graphics.</a></li>
<li><a href="https://www.aptech.com/blog/how-to-interactively-create-reusable-graphics-profiles/">How to Interactively Create Reusable Graphics Profiles.</a></li>
</ul>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/how-to-create-tiled-graphs-in-gauss/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Basics of GAUSS Procedures</title>
		<link>https://www.aptech.com/blog/basics-of-gauss-procedures/</link>
					<comments>https://www.aptech.com/blog/basics-of-gauss-procedures/#comments</comments>
		
		<dc:creator><![CDATA[aptech]]></dc:creator>
		<pubDate>Fri, 17 Jul 2020 20:47:27 +0000</pubDate>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Programming]]></category>
		<guid isPermaLink="false">https://www.aptech.com/?p=22355</guid>

					<description><![CDATA[GAUSS procedures are user-defined functions that allow you to combine a sequence of commands to perform desired tasks. In this blog, you will learn the fundamentals of creating and using procedures in GAUSS.]]></description>
										<content:encoded><![CDATA[<h3 id="introduction">Introduction</h3>
<p>Our goal for this post is to learn the fundamentals of creating and using procedures in GAUSS. When you are finished, you should be able to create GAUSS procedures and use those written by others.</p>
<h2 id="what-is-a-gauss-procedure">What is a GAUSS Procedure?</h2>
<p>GAUSS procedures are user-defined functions. They allow you to combine a sequence of commands to perform a desired task.</p>
<div class="su-quote su-quote-style-default su-quote-has-cite"><div class="su-quote-inner su-clearfix"><span class="su-quote-cite">
<p>A function is a block of organized, reusable code that is used to perform a single, related action. - Tutorialspoint.com</p>
</span></div></div>
<h2 id="why-create-gauss-procedures">Why Create GAUSS Procedures?</h2>
<p>There are many advantages to creating GAUSS procedures. Even if you don’t consider yourself a programmer, creating GAUSS procedures will make your work easier and more productive.</p>
<p><strong>Save time.</strong> Every time you use a previously written GAUSS procedure you,</p>
<ul>
<li>Avoid rewriting the same code.</li>
<li>Avoid debugging new or old mistakes.</li>
<li>Keep your main code simpler and more readable.</li>
</ul>
<h2 id="how-to-create-a-gauss-procedure-definition">How to Create a GAUSS Procedure Definition</h2>
<p>Let’s start with a simple example. We’ll create a simple procedure named <code>power</code> which takes two inputs and returns one output.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (1) = power(X, p); // 1. Procedure declaration
    local X_out;        // 2. Local variable list

    X_out = X ^ p;      // 3. Procedure body

    retp(X_out);        // 4. Procedure return
endp;                   // 5. Procedure end</code></pre>
<p>Each line in the above procedure is one of the main parts of a GAUSS procedure. Now let's discuss the details of each of these elements.</p>
<h3 id="1-the-procedure-declaration">1. The Procedure Declaration</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">a.         c.
↓          ↓
proc (1) = power(X, p);
      ↑          ↑
      b.         d.</code></pre>
<p>The procedure declaration is the first line of all GAUSS procedures. It contains four main sections:</p>
<table>
<thead>
<tr>
<th></th>
<th></th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>a.</td>
<td><code>proc</code></td>
<td>Keyword that starts the procedure declaration.</td>
</tr>
<tr>
<td>b.</td>
<td><code>(1) =</code></td>
<td>The number of items (matrices, strings, etc) that will be returned by this procedure. It is optional with a default value of 1.</td>
</tr>
<tr>
<td>c.</td>
<td><code>power</code></td>
<td>The name of the procedure.</td>
</tr>
<tr>
<td>d.</td>
<td><code>(X,p)</code></td>
<td>The required input arguments.</td>
</tr>
</tbody>
</table>
<p>Don't forget the ending semi-colon.</p>
<h3 id="2-the-local-variable-list">2. The Local Variable List</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">    local X_out;  </code></pre>
<p>The local variable list is a comma-separated list of variables that will be used inside the procedure. These local variables only exist when the procedure is running.</p>
<h3 id="3-the-procedure-body">3. The Procedure Body</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">    X_out = X ^ p;</code></pre>
<p>The procedure body is where the procedure's computations are performed. In this case, we have just one simple line. However, there is no limit to the size of your procedure. </p>
<p>You can use procedures created by you or others as well as any built-in GAUSS function or operator inside the body of your procedure.</p>
<h3 id="4-the-procedure-return">4. The Procedure Return</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">    retp(X_out);</code></pre>
<p>You can return any of the local variables from the procedure, or none at all. When returning more than one variable, use commas to separate the variable names.</p>
<h3 id="5-the-procedure-end">5. The Procedure End</h3>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">endp;</code></pre>
<p>The <code>endp</code> keyword signals the end of the procedure.
<span id="define_procs"></span></p>
<h2 id="how-to-use-a-gauss-procedure">How to Use a GAUSS Procedure</h2>
<p>There are two steps required to use a GAUSS procedure:</p>
<ol>
<li>Define the procedure.</li>
<li>Call the procedure.</li>
</ol>
<h3 id="how-to-define-a-gauss-procedure">How to Define a GAUSS Procedure</h3>
<p>When GAUSS first starts up, it is only aware of its own built-in functions and procedures. Defining a procedure is the process of making GAUSS aware of your procedure. If you try to use a procedure before it is defined, like this:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Clear all data and procedures from the GAUSS workspace
new;

// Call procedure that has not been defined
power(3, 2);</code></pre>
<p>you will get the error <code>G0025 : Undefined symbol: 'power'</code>.</p>
<p>Here are four ways to define your GAUSS procedure:</p>
<ol>
<li>Add the procedure to your main code file.</li>
<li>Run the GAUSS procedure.</li>
<li>Place the procedure in a <code>.g</code> file.</li>
<li>Add your procedure to a GAUSS library.</li>
</ol>
<p><strong>1. Add the procedure to your main code file.</strong> The simplest method to define a procedure is to simply add it to your code and run the main file. This allows for a natural process of learning-by-doing.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/07/blog-gauss-procedure-basics-run-file-2.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/07/blog-gauss-procedure-basics-run-file-2.jpg" alt="Run a GAUSS program with a procedure." width="453" height="408" class="aligncenter size-full wp-image-22458" /></a></p>
<p>As we can see from the above image, the procedure can be included anywhere in your program file. It is often convenient to place procedures after the main code.</p>
<p>GAUSS can allow this because it does not just run your code line-by-line. It is smarter than that. When GAUSS runs your program, its first step is to compile your code. This allows GAUSS to find many mistakes immediately and also speed-up your code in addition to locating your procedures.</p>
<p><strong>2. Run the GAUSS procedure.</strong> Since GAUSS does not run your code line-by-line, as we saw in the previous section, GAUSS needs to have the entire procedure definition at once. Therefore, you cannot run a procedure one line at a time. If you try to run the first line alone:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">proc (1) = power(X, p);</code></pre>
<p>you will get the error <code>G0278 : PROC without ENDP 'power'</code>.</p>
<p>After you run the entire procedure:</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/07/blog-gauss-procedures-basics-run-highighted-text.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/07/blog-gauss-procedures-basics-run-highighted-text.jpg" alt="Run a GAUSS procedure." width="529" height="415" class="aligncenter size-full wp-image-22463" /></a></p>
<p>the procedure is defined so that you can use it in GAUSS. Now running:</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">x = power(3, 2);
print x;</code></pre>
<p>will be successful, returning:</p>
<pre>9</pre>
<p><span id="dot_g_proc_file"></span></p>
<p><strong>3. Place your procedure in a .g file.</strong> It is not always convenient to keep all procedures in your main code file.</p>
<p>A simple alternative is to:</p>
<p>    i. Create a file with the same name as your procedure plus a <code>.g</code> file extension. Such as <code>power.g</code>.<br/>
    ii. Place your procedure in this file.<br/>
    iii. Save this file in a location where GAUSS can find it.</p>
<div class="alert alert-info" role="alert">GAUSS will search for this file first in your <a href="https://www.aptech.com/blog/the-current-working-directory-what-you-need-to-know/">Current Working Directory</a>, then it will search your <a href="https://www.aptech.com/resources/tutorials/src_path/">SRC_PATH</a>.</div>
<p><strong>4. Add your procedure to a GAUSS library.</strong> Adding your related procedures to a GAUSS library is considered a best practice. GAUSS libraries make it easier to use and share code without worrying about paths.</p>
<p><a href="https://www.aptech.com/wp-content/uploads/2020/07/gauss-procs-library-tool.jpg"><img src="https://www.aptech.com/wp-content/uploads/2020/07/gauss-procs-library-tool.jpg" alt="GAUSS Library Tool." width="50%" height="50%" class="aligncenter size-full wp-image-22431" /></a></p>
<p>Full GAUSS library management is beyond the scope of this article. However, the above image shows the <strong>Create Library</strong> and <strong>Add Files</strong> controls.</p>
<h3 id="how-to-call-a-gauss-procedure">How to Call a GAUSS Procedure</h3>
<p>Now that we've learned how to create and define GAUSS procedures, it's time to use them. Here are a few example procedures to fill in anything you might be unsure about.</p>
<p>We'll start with a procedure with two returns.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create 4x1 vector
y = { 1, 3, 2, 1 };

// Call procedure
{ a, b } = range(y);

// Print results
print "The smallest value is: " a;
print "The largest value is : " b;

// Procedure that returns two items
proc (2) = range(X);
    local min, max;

    min = minc(X);
    max = maxc(X);

    retp(min, max);
endp;</code></pre>
<p>Running the above code will return:</p>
<pre>The smallest value is:        1
The largest value is :        3</pre>
<p>Next, we'll consider a case with two inputs.</p>
<pre class="hljs-container hljs-container-solo"><code class="lang-gauss">// Create 5x1 vector
z = { 1, 2, 3, 4, 9 };

m1 = average(z, "median");
print m1;

m2 = average(z, "mean");
print m2;

proc (1) = average(y, type_);
    local avg;

    if type_ $== "mean";
        avg = meanc(y);
    elseif type_ $== "median";
        avg = median(y);
    else;
        print "Second input, type_, not recognized";
        end;
    endif;

    retp(avg);
endp;</code></pre>
<p>which will return:</p>
<pre>3.0
3.8</pre>
<h3 id="conclusion">Conclusion</h3>
<p>Great job! You've made it through the fundamentals of GAUSS procedures. You've learned:</p>
<ol>
<li>The parts that make up a GAUSS procedure.</li>
<li>How to define GAUSS procedures.</li>
<li>How to call GAUSS procedures.</li>
</ol>]]></content:encoded>
					
					<wfw:commentRss>https://www.aptech.com/blog/basics-of-gauss-procedures/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
