Thursday, April 17, 2014

Is It Worth Risking the Caltrain Fine Instead of Buying a Ticket?

I take the techno-elite bus to work (you know, those ones that are becoming increasingly popular with the locals). Since the bus only leaves / departs once per day, I occasionally take Caltrain for one leg of the journey.

Caltrain is a proof-of-payment system. You can simply waltz onto the train without paying, but the conductor issues stern warnings that Caltrain retains the right to check your ticket and issue fines.

Should you actually buy a ticket? To the economically trained, this becomes an intriguing empirical question, solved by the expected-value equation.

Using my Clipper stored-valued card, I ride three zones, which costs $6.75 (see full fare chart). Getting an estimate on the fine is a little tougher. A Yelp post from 2007 says the fine is $300, while another blogger who asked himself this same question in 2012 cites $250. Let's go with the $250 number, since it's more recent, and it can bias my answer toward "you should not pay" (the outcome that all economists are secretly rooting for).

The equation would be as follows: 250x = 6.75, where x is the percentage chance that they'll check my ticket. Turns out that if tickets are checked any more frequently than 2.7% of the time,  you should buy a ticket. Things actually are a bit worse than that, as this equation doesn't factor in the shame you may feel if the conductor yells at you, the anxiety you may feel worrying about whether tickets are checked, or the hassle of physically paying the fine. On the flip side, maybe you could contest the assumption that you'll have to pay 100% of the time when they find you without a ticket, depending upon how good you at sweet-talking or claiming to be a clueless tourist. My wife's cousin also suggests that the "the machine wasn't working for me" excuse might work better if you actually have a Clipper card in your pocket instead of arguing that you were trying to buy a paper ticket but failed.

How often does Caltrain check tickets? Estimates vary widely: I have ridden Caltrain from Millbrae to San Jose or vice versa 10 times and have yet to be checked. My wife's cousin estimates that tickets are checked 1 in 6 times. The aforementioned blogger experienced checks on 45% of his rides in 2012.

Even though I've yet to see a Caltrain ticket check myself, I have to put my Bayesian reasoning to work here and assume the true rate is at least 2.7%. So while I can't squeeze any gains out of a government agency this time, at least I had fun trying.

Tuesday, April 15, 2014

Forgetting the Details

On rare occasions, I get so engrossed in good articles from Grantland and the like during my hour-long bus ride to or from work that I don't want the ride to end.

I felt this a few days ago. But I realize that if you asked me now what any of the articles were about, I'd have no clue. Part of me wants to think that I've somehow internalized the information (like how people say "I think I read that somewhere"). But let's assume I didn't; I've heard (somewhere) that we remember 10% of what we read. Did that defeat the purpose of reading? My answer is no. It gave me satisfaction in the moment, and I remember that satisfaction later. I think the concept could apply to any other fleeting activity I could have been doing with my phone during that bus ride, or a conversation I could have been having.

I have a pretty solid email correspondence with one of my buddies back in D.C. How many of our conversations or emails do I remember in any detail? It's almost certainly less than half. But just remembering the highlights and knowing "I've had lots of great conversations and emails with this friend" is enough for me.

Saturday, February 15, 2014

From Vegan to Hunter

I'm a fan of Siddhartha-esque journeys. In Siddhartha's case, he explored the entire spectrum of religion, from starving as an ascetic to engaging in high-stakes gambling, only to settle down on the river, in the literal and figurative middle.

The Mindful Carnivore: A Vegetarian's Hunt for Sustenance is same for food, as we watch the author, Tovar Cerulli, embrace veganism and then become a hunter over the course of many years.

For me, eating meat was always a cognitive dissonance. I like meat, eat if often, but am only occasionally reminded of its gruesome origins. We dote on our cat, Apollo, buying him endless toys, making sure to mentally stimulate him, paying someone to come check on him daily when we're out of town, and feeling guilty if we are out for dinner or drinks and miss his feeding schedule by a few hours. Imagine the horror that would occur in my household if I took out our sharpest knife from the kitchen, grabbed Apollo, and slit his throat. Sharon would instantly divorce me, and I might even end up in jail. Yet week after week, we bring home meat from the grocery store, dissociated from its former animal, "a gaping chasm between field and table," as Cerulli writes. Why are some animals endeared and others mindlessly eaten? This is a topic also covered in depth in the book Some We Love, Some We Hate, Some We Eat.

As an economist, I've never much bought into the categorical imperative: "Act only on that maxim through which you can at the same time will that it should become a universal law." Sure, maybe I could adopt a lifestyle that involves veganism or diligent recycling, but even if I do, the aggregate impact on the world is squat. In fact, I might be more easily persuaded to vote a citywide ban on plastic grocery bags than I would be to use reusable bags on my own, as the latter has so little impact. Thinking through the supply chain for food -- from farmer to wholesaler to stores and restaurants -- it's hard to prove that a lifetime of veganism would save even a single animal.

Cerulli also comes to the realization that being a vegan and growing his own food aren't harmless. This is a man who buys Christmas trees near power lines, figuring that they will be cut down anyway, and who has an ethical dilemma over killing an insect. Yet as he tried to grow his own food, he kept having his crops ravaged by gophers and deer. After failed attempts to quell the problem by capturing and relocating the gophers and building more elaborate fencing, he came to the realization that he needed to start shooting them with his BB gun. He then learned from others farmers about how many deer need to be killed to protect their crops. The growth of non-meat foods still involves plenty of indirect death. So he starts thinking about the cycle of life and death more deeply, a journey that progresses until he himself becomes a hunter in order to come face to face with the act of killing an animal for meat.

The resolution may come for one innovations that I'm most hoping for in the coming years: synethic meat. Hopefully someday, we can get the same taste, pleasure, and nutrition without the death.

One other loose end from the book that I found interesting: The campaigns for eating vegetables and curbing animal cruelty were initially totally separate. There were ads in the early 1900s about how vegetarian diets helped the University of Chicago football team play so well and be so manly.

Friday, February 14, 2014

Looping with SAS Macros

SAS macros can be used to loop through any list stored in a string of text and do a repetitive process on each element of the list. You can also create a list dynamically from an existing SAS dataset.

Step 1: Read in a list of states of abbreviations from an existing dataset

First, you need to create your list of elements. It can be as simple as listing them in a macro variable:

%let list = apple banana grape;

Or you can read them from an existing SAS dataset using "separated by." In this example, I am reading two lists: states and state abbreviations. Notice that I'm separating my state list by slashes, so that "Rhode" and "Island" won't look like two different elements when it comes time to loop. 

proc sql noprint;
select state, abbr into : full_list separated by "/", : abbr_list separated by " " from greg.states;

Step 2: Count the elements in the list

Now, I'm going to invoke a macro to count the number of elements in the list. Because both of my lists are the same number of elements, I only need to do this once. I start at 0, then increment by 1 each time I scan through the list and see another string of text separated by my delimiter (here, a slash).

%macro varcount;
%global var_num;
%let var_num=0;
%do %while(%qscan(&full_LIST,&var_num.+1,"/") ne %str());
%let var_num = %eval(&var_num+1);
%mend varcount;

Step 3: Assign each element in to a numbered macro variable

Now, I am going to use the count I got above and loop through s times, from 1 to the maximum value. Each time I go through the loop, I'm going to define a numbered macro variable. The first full name will be "Alabama", stored in a macro variable called "full1". The first abbreviation will be "AL", stored in a macro variable called "abbr1". The repeats all the way through "full51" and "abbr51".

%macro numvars;
%do s =1 %to &var_num;
%global full&s. abbr&s.;
%let full&s. = %qscan(&full_LIST.,&s,"/");
%let abbr&s. = %qscan(&abbr_LIST.,&s," ");
%mend numvars;

Step 4: Loop through each element

Here is where the magic starts to happen. I am again looping through s, from 1 to the number of elements that I have. Each time I'm in the loop and want to refer to a state, I should use &&full&s..

As SAS revolves macros, it turns two &'s into one, and turns single & into the macro variable name it finds up until a period.

Original: &&full&s..
First pass (when s = 1): &full1
Second pass (look for value of &full1): Alabama

Within the loop, you can put ANY TEXT, and it will be repeated for each element in the list. Here, I will get a case statement with 51 when clauses, one for each state. Notice that the macro is invoked below, in the proc sql step. You can do pieces of a step like I've done here, or you can have a full step, or 50 full steps. I could start with a step where I am making a data set using only the Alabama rows, and then I can do a ton of transformations on it, then repeat for each new step. The possibilities are endless!

%macro states;
%do s = 1 % to &var_num;
when "&&full&s.." then "&&abbr&s.."
%mend states;

Proc sql;
select case %states end as state_abbr from full_states;