About

Robert FornangoRobert Fornango, PhD

I am a data scientist. Part data analyst, part social scientist. And I want to help share what I’ve learned about data analytics and coding across various statistical computing platforms, including R, Stata, and Excel.

I’m also an avid cyclist.

My interest is in seeing new analysts become successful data scientists. And if my experiences can help you succeed, that would be awesome! While I have a good deal of experience with analytics, this profession really is one of constant learning. So, as I learn more, I’ll share more…please feel free to jump into the discussion and let me know what you’re interested in learning, and if my work is helping.

I love a good chimichanga!

My background is in criminology, a multi-disciplinary science comprised of sociology, psychology, political science, economics, and public policy. I spent 10 years teaching statistics, research methods, and theory at the undergraduate, Masters, and PhD level in the university.

My girlfriend and I have a Yorkie and a Cairn Terrier that enjoyed joint custody between our home and her mother’s home.

Over the years I have had the opportunity to engage in both primary data collection, and secondary data analysis. My analyses have incorporated multi-level modelling, panel data analysis, spatial regression, and a variety of other tools. And I’ve learned to use several different statistical programs proficiently, including R, Stata, SPSS, SAS, and Excel.

These days, I primarily use Excel, R, and Stata…so these will be my focus at the outset here. Hopefully, if you find my work useful I’ll have the opportunity to write about SPSS and SAS as well.

Recent Posts

Expressing Pi in Your Favorite Statistical Software

Pi_Warhol_sTo celebrate Pi Day, and provide some (hopefully) useful knowledge, I’ll show you how to represent Pi in your favorite statistical packages.

If your favorite isn’t on the list, I’m sorry…I can only do so much.

One thing to keep in mind about these examples is that most software packages use floating point arithmetic (FPA).

I won’t get into exactly what this means in this post. Just know that FPA will generally result in some rounding errors with highly precise numbers (i.e. lots of decimal places). However, below 16 decimal places, you can be reasonably assured that these packages return the same values.

Excel

=PI()

Note this function does not have any arguments. The value returned is accurate to 14 decimal places.

R

>pi

This returns pi to 6 decimal places. If you need more precision, you can get up to 15 decimal places with the following code (the integer 3, is the 16th digit):

>options(digits=16)
>pi

The digits option can go as high as 22, but the default R algorithm is only accurate up to 15 decimal places (see http://www.joyofpi.com/pi.html).

For greater precision, I recommend using the Rmpfr package. I set it to 256-bit precision, and achieved accuracy up to 75 decimal places.

Stata

. di c(pi)
or
. di _pi

As with R, the default precision is 6 decimal places. If you need to increase the precision, you can format the constant for up to 16 decimal places.

.di %19.0g _pi

SAS

I know less about the nuances of representing Pi in SAS. But my research in the SAS documentation suggests that pi can be stored with precision above 16 decimal places.

The basic code is:

data _null_;
  pi=constant('pi');
  put pi=;
run;

SPSS

This may be the worst package to use for representing pi, as IBM still has not included pi as a system constant in the program. Instead, we get to make use of our knowledge in trigonometry (did you just cringe? I did.)…

If you dig back far enough in your memory, you might recall that the tangent of (pi/4) =1. Using the inverse tangent function (the arctangent), you can create a variable to represent pi:

compute  pi = 4*ARTAN(1).

Hope you find this interesting and useful…Happy Pi Day!

  1. Simulating Data with A Known Correlation Structure in Stata Leave a reply
  2. Taking Stata for a Loop: -forvalues- 3 Replies
  3. How to Preserve Missing Values with Stata’s Collapse Command 3 Replies
  4. How to Call R from Stata 7 Replies
  5. Adding Code Snippets to Your WordPress Posts 5 Replies
  6. Data Analytics and the Three-Headed Monster Leave a reply