Econometrics with Gretl — Building a GeoSegmentation Model for Bank Churn
Econometrics with Gretl — Building a GeoSegmentation Model for Bank Churn

What is Gretl?

Gretl is an open source statistics package that was developed for econometrics but can be used for a wide variety of data. The program is written in C++ and has many community sourced packages that extend the core program.

The program can be downloaded here and the data used in this tutorial can found on Kaggle here.

Taking a look at the data

The data can be loaded into Gretl from File and selecting the downloaded csv. The program will alert the user that the data is undated and will ask if it should attempt to construct a time series, for this data set we won’t need to do that.

Two windows are present, one containing variable string values named string_table.txt and the main Gretl window showing the entire list of variables present in the data.

Dummy variables

The variables Gender and Geography need to be encoded numerically and this can be done in Grelt by right clicking on the variable in the main screen and choosing Dummify and then Encode all values. To make things simpler, expand the Geography and Gender variables and edit the attributes for the values. For example, right clicking France under Geography and choosing “edit attributes” to change the name field from DGeography_1 to France.

Examining the variables

Exited is the dependent variable as its the outcome of interest, and this case study examines the factors that may be associated with a person leaving or staying at the bank. Variables such as RowNumber, CustomerID, and Surname do not affect whether a person stays or leaves the bank and therefore these columns are not used. The remaining variables will be the regressors.

CreditScore — A customers credit score can affect their decision

— A customers credit score can affect their decision Geography — Regional data for where the customers are located

— Regional data for where the customers are located Gender — The gender of a customer may play a role in whether they stay or leave

— The gender of a customer may play a role in whether they stay or leave Age — The age of a customer

— The age of a customer Tenure — The duration of a customers dealings with a bank — a longer tenure may build loyalty

— The duration of a customers dealings with a bank — a longer tenure may build loyalty Balance — A customers bank balance — could affect promotions, interest rates, and account fees

— A customers bank balance — could affect promotions, interest rates, and account fees NumOfProducts — How many products a customer subscribes to — more products may lead to higher chances of staying

— How many products a customer subscribes to — more products may lead to higher chances of staying HasCrCard — If a customer has a credit card with the bank or not — increases the banks presence in a customers life

— If a customer has a credit card with the bank or not — increases the banks presence in a customers life IsActiveMember — Customers activity with bank in the last 6 months — active customers could be more likely to stay

— Customers activity with bank in the last 6 months — active customers could be more likely to stay EstimatedSalary — Banks estimate of a customers salary — higher earners may have more investments with the bank

— Banks estimate of a customers salary — higher earners may have more investments with the bank Exited — Whether a customers stays with the bank or leaves

Building the model

Gretl makes modeling the data very easy. It’s done by going to the Model tab in the main window and navigating to limited dependent variable (since exited is a discrete variable) and then to logit (logistic regression) and lastly to binary.

Model -> limited dependent variable -> logit -> binary

Gretl will then prompt the user to choose the dependent variables (Exited) and the regressors (the list above). In order to determine the significance of variables in the model, the show p-values box should be checked. Run the model.

Dropping variables

Running the first regression iteration results in the following coefficients and p-values:

Model iteration 1

It can be seen that the highest p-value was for Spain, which indicates that it is not a significant variable, therefore we can exclude Spain from the model. When modeling the data again without Spain, the accuracy does not increase and the R-squared value increases very slightly:

Model iteration 2

HasCrCard and EstimatedSalary are removed as these variables have the next highest p-values (above 0.05). After running the model again without these two variables there is a slight increase in accuracy and R-squared score. Ideally, there shouldn’t be variables with a p-value above 0.05 but Tenure is around 0.087. Tenure could be removed but logically it makes sense that the duration of a customers relationship with the bank plays a role in their staying or leaving. Now the model shows no variables with a p-value above the threshold (except Tenure):

Model iteration 3

Log transformation — Balance

Since balance has a large range and a one unit increase from 1000$ to 2000$ shows a doubling effect while a unit increase from 10,000$ to 11,000$ is only a 10% increase, the values need to be transformed so they scale. To do this the log will be taken and 1 will be added to each row in case there’s a 0 balance.

This is done in Gretl by defining a new variable and entering the equation log10(balance + 1). The following are the results with replacing balance with log_Balance:

Model iteration 4

Derived variable — Wealth_Accumulation

A derived variable may represent some fields such as balance and age more accurately. For example, younger people may have smaller balances and older people may have larger balances that grow with age. Alternatively, a young person may have a lucrative job and have a larger balance compared to an older person who may have lost their savings. This metric may better represent the financial position of customers.

To create this derived variable, the log balance in a bank account can be divided by the age of the account holder. This variable is termed Wealth_Accumulation. The following results are obtained with Wealth_Accumulation as a part of the equation:

Model iteration 5

Dealing with multicollinearity

Having Wealth_Accumulation, Log_Balance, and age in the model may show a decrease in accuracy and a high p value as there is likely multicollinearity. Gretl can check for collinearity and the variance inflation factor (VIF). The VIF for Log_balance and Wealth_Accumulation are much higher than the other variables:

VIF with Log_Balance and Wealth_Accumulation

When taking out Log_Balance, the coefficient for Wealth_Accumulation deflates:

VIF with only Wealth_Accumulation

The metrics for the model containing only Wealth_Accumulation are:

Model performance with Wealth_Accumulation

Taking the log of Wealth_Accumulation may possibly be a better metric than the non-transformed variable. Including both log balance and log wealth accumulation shows the effects of collinearity with both VIF scores being ~700.

This collinearity effect can be further seen by taking the log of Wealth_Accumulation and including it in the equation along side Log_Balance:

VIF with Log_Wealth_Accumulation and Log_Balance

The metrics for the model containing both the Log_Balance and Log_Wealth_Accumulation variables are:

Model performance with Log_Wealth_Accumulation and Log_Balance

When assessing performance with only Log_Wealth_Accumulation the metrics are:

Model performance with only Log_Wealth_Accumulation

Finalizing a model

When comparing the two models where one uses only Log_Wealth_Accumulation and the other only Log_Balance, the model with Log_Balance results in the higher R-squared score (0.151006) and an accuracy only one correct prediction short of the Log_Wealth_Accumulation accuracy (8127 vs 8128).

Results — Which variables have the most impact?

In order to determine which variables are the most important in determining the banks churn rates, the odds ratios for each coefficient need to be calculated.

Calculating the odds ratio

The equation for simple logistic regression:

The odds equation:

Subbing odds into the logistic regression equation (also known as log odds):

Take the exponent of each side:

Simplified:

Increasing a variable by one unit:

The exponents show that an increase of one unit leads to a multiplicative effect:

Calculating the odds ratios in Gretl

These ratios can be calculated in Gretl using the function package “odds ratios”:

Conclusion — Who can the bank target to reduce churn?

The results show that the most impactful variables are being German, female, and being an active member. The odds-ratio in this case is looking at which factors contribute to a customer leaving. Therefore, when looking at this bank’s churn, a customer living in Germany or moving there increases their odds of leaving by a factor of 2.1119. Further, a customer being a female increases their odds of leaving by a factor of 1.6934. Being an active member on the other hand is indicative of a customer staying with the bank. Ultimately, if the bank would like to reduce churn and retain their customer base they would have to target their German customers — especially German females — and work on increasing these customer’s activity with the bank.
['Gurkamal Deol']
['Predictive Analytics', 'Data Science', 'Economics', 'Statistics']