<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Abed Nigo on Medium]]></title>
        <description><![CDATA[Stories by Abed Nigo on Medium]]></description>
        <link>https://medium.com/@myniggname?source=rss-8ff33be0853e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*U5vGchP4WwHf51uS</url>
            <title>Stories by Abed Nigo on Medium</title>
            <link>https://medium.com/@myniggname?source=rss-8ff33be0853e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 18:25:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@myniggname/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Bigquery Project: Recreate Cohort Analysis of  Users Engangement on Stackoverflow Dataset Part-1]]></title>
            <link>https://medium.com/@myniggname/bigquery-project-recreate-cohort-analysis-of-users-engangement-on-stackoverflow-dataset-part-1-fc3f8bd81c55?source=rss-8ff33be0853e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc3f8bd81c55</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-visualisation]]></category>
            <category><![CDATA[data-analytics]]></category>
            <category><![CDATA[bigquery]]></category>
            <dc:creator><![CDATA[Abed Nigo]]></dc:creator>
            <pubDate>Tue, 23 Jul 2024 05:04:16 GMT</pubDate>
            <atom:updated>2024-07-23T05:04:16.312Z</atom:updated>
            <content:encoded><![CDATA[<h3>Bigquery Project: Recreate Cohort Analysis of Users Engangement on Stackoverflow Dataset Part-1</h3><h3>Introduction</h3><p>In the world of data analytics, cohort analysis is a powerful tool that helps businesses understand user behavior over time. By grouping users based on shared characteristics and tracking their actions, we can gain valuable insights into retention, engagement, and overall product performance. In this part, I will walk you through how to create a cohort analysis using BigQuery on Stackoverflow dataset.</p><h3>What is Cohort Analysis?</h3><p>Cohort analysis is a subset of behavioral analytics that takes data from a given dataset and rather than looking at all users as one unit, it breaks them into related groups, or “cohorts”. This analysis allows us to observe how the behavior of these groups changes over time especially from the perspective of post questions dataset from Stackoverflow.</p><h3>Why Stack Overflow Data?</h3><p>Stackoverflow, being a rich source of developer-centric data, provides an excellent opportunity to perform meaningful cohort analysis. We can analyze how users engage with the platform over time, how retention rates change, and what factors contribute to user loyalty. This study case will come in segments, the focus of this part shows brief analysis on the perspective of users who post questions on Stackoverflow.</p><h3>Setting Up BigQuery</h3><p>Before we dive into the analysis, I assume that you are familiar with Google account and its related products and ensure that you have access to Google BigQuery. If you don’t have it already, you can set up a free account with Google Cloud Platform (GCP).</p><ol><li><strong>Create a New Project</strong>: Log in to GCP and create a new project.</li><li><strong>Enable BigQuery API</strong>: Navigate to the API library and enable BigQuery API for your project.</li><li><strong>Access Stack Overflow Data</strong>: Stack Overflow dataset is publicly available in BigQuery’s public datasets.</li></ol><h3>Data Preparation</h3><ol><li><strong>Load the Data</strong>: First, we need to load the Stack Overflow data into BigQuery. You can find the dataset under bigquery-public-data.stackoverflow.</li><li><strong>Understand the Schema</strong>: Familiarize yourself with the structure of the data, especially focusing on tables ofposts_questions. The dataset has 20 columns and 2.3020.127 million rows. This analysis will show the users behavior on 2020 and 2021.</li></ol><h3>Writing the Query</h3><p>We will write a SQL query to perform the pre-cohort analysis. The goal of the first business question in this part is finding the visual user behavior for some period of times.</p><p>Step 1. Query for Cohort Items Table</p><pre>--Query to return Cohort Items table<br>select <br>  owner_user_id as user_id,<br>  min(date(date_trunc(creation_date, month))) as cohort_month<br>from `bigquery-public-data.stackoverflow.posts_questions`<br>group by user_id<br>order by user_id desc; </pre><p>This step has the objective to return the value of user_id and the cohort_month</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oyKjeascpo_hkVKoHnGNqg.png" /></figure><p>Step 2. Query for Users Activities Table</p><pre>--Query to return Users Activities table<br>with cohort_items as (<br>  select <br>    owner_user_id as user_id,<br>    min(date(date_trunc(creation_date, month))) as cohort_month<br>  from `bigquery-public-data.stackoverflow.posts_questions`<br>  group by user_id<br>)<br>select<br>  activities.owner_user_id as user_id,<br>  date_diff(date(date_trunc(creation_date, month)),<br>  cohort.cohort_month, month) as month_number,<br>from `bigquery-public-data.stackoverflow.posts_questions` activities<br>left join cohort_items cohort on activities.owner_user_id = cohort.user_id<br>where extract(year from cohort.cohort_month) in (2020, 2021)<br>group by user_id, month_number;</pre><p>This step 2 will return the value of user_id and the month_number</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7_2S44V-HSC9z-UtlL68Vw.png" /></figure><p>Step 3. Query for Cohort Size Table</p><pre>--Query to return Cohort Size<br>with cohort_items as (<br>  select <br>    owner_user_id as user_id,<br>    min(date(date_trunc(creation_date, month))) as cohort_month<br>  from `bigquery-public-data.stackoverflow.posts_questions`<br>  group by user_id<br>)<br>select <br>    cohort_month,<br>    count(cohort_month) as num_users,<br>from cohort_items<br>group by cohort_month<br>order by cohort_month; --order by is optional, only to show on this code block</pre><p>This step 3 will return the value of cohort_month and the num_users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*egPBhRdbDC9LLYi8_JhJMg.png" /></figure><p>Step 4. Query for Retention Table</p><pre>--Query to return Retention Table<br>with cohort_items as (<br>  select <br>    owner_user_id as user_id,<br>    min(date(date_trunc(creation_date, month))) as cohort_month<br>  from `bigquery-public-data.stackoverflow.posts_questions`<br>  group by user_id<br>),<br>users_activities as (<br>  select<br>    act.owner_user_id as user_id,<br>    date_diff(date(date_trunc(creation_date, month)),<br>    cohort.cohort_month, month) as month_number,<br>  from `bigquery-public-data.stackoverflow.posts_questions` act<br>  left join cohort_items cohort on act.owner_user_id = cohort.user_id<br>  where extract(year from cohort.cohort_month) in (2020, 2021)<br>  group by user_id, month_number<br>)<br>select<br>  Cohort.cohort_month,<br>  Activities.month_number,<br>  count(cohort.cohort_month) as num_users<br>from users_activities Activities<br>left join cohort_items Cohort on Activities.user_id = Cohort.user_id<br>group by Cohort.cohort_month, Activities.month_number<br>order by Cohort.cohort_month, Activities.month_number;<br>--order by is optional, only applies in this block code to show ascending order</pre><p>This step 4 will return the value of cohort_month, month number, and the num_users</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ofK_YMoNmQpIo7YP-y5dnw.png" /></figure><p>Step 5. Query for Cohort Table</p><pre>--Complete Code for Cohort Table<br>with cohort_items as (<br>  select <br>    owner_user_id as user_id,<br>    min(date(date_trunc(creation_date, month))) as cohort_month<br>  from `bigquery-public-data.stackoverflow.posts_questions`<br>  group by user_id<br>),<br>users_activities as (<br>  select<br>    act.owner_user_id as user_id,<br>    date_diff(date(date_trunc(creation_date, month)),<br>    cohort.cohort_month, month) as month_number,<br>  from `bigquery-public-data.stackoverflow.posts_questions` act<br>  left join cohort_items cohort on act.owner_user_id = cohort.user_id<br>  where extract(year from cohort.cohort_month) in (2020, 2021)<br>  group by user_id, month_number<br>),<br>cohort_size as (<br>  select <br>    cohort_month,<br>    count(cohort_month) as num_users,<br>  from cohort_items<br>  group by cohort_month<br>),<br>retention_table as (<br>  select<br>    Cohort.cohort_month,<br>    Activities.month_number,<br>    count(Cohort.cohort_month) as num_users<br>  from users_activities Activities<br>  left join cohort_items Cohort on Activities.user_id = Cohort.user_id<br>  group by Cohort.cohort_month, Activities.month_number<br>)<br>select<br>  Retention.cohort_month,<br>  Size.num_users as cohort_size,<br>  Retention.month_number,<br>  Retention.num_users as total_users,<br>  cast(Retention.num_users as decimal)/Size.num_users as percentage<br>from retention_table Retention<br>left join cohort_size Size on Retention.cohort_month = Size.cohort_month<br>where Retention.cohort_month is not null<br>order by Retention.cohort_month, Retention.month_number;</pre><p>This cohort table query will return the value of cohort_month, cohort_size, month number, total_users, and the percentage as seen below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ynzg-TKN-YR_AorMqRhKww.png" /></figure><p>It is necessary to download the result in google sheet then create the pivot table with the rows of cohort_month and cohort_size, then add month_number in the column, put percentage in the values. The google sheet link can be accessed <a href="https://docs.google.com/spreadsheets/d/1Nm3Wpg9p1S4f98rQTPoqORyiCUr6P11J7ZxSiZBvVCU/edit?usp=sharing">here</a>:</p><h3>Analyzing the Results</h3><p>Once the query is executed, you’ll get a table with cohort_year, cohort_month, activity_year, activity_month, and retention_rate. This data shows the retention rate of users who signed up in a particular month and year, tracked over subsequent months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lirx1jSuT15SeGiWgDOr8Q.png" /></figure><p>I put the PDF link of the result <a href="https://drive.google.com/file/d/13iW8-o6VDm24bVbb1auD7kjSLqTDbp67/view?usp=sharing">here</a>.</p><p>The analysis will need further understanding to gain insight on the user behavior from post_questions dataset. So far, the percentage numbers from month 0 to 1 have shown the ratio of the users who have engage in the platform. Next part will discuss deeper insight to gain knowledge in the users behavior.</p><p>Feel free to reach out with any questions or comments. Happy analyzing!</p><h3>About the Author</h3><p>My name is Abed Nigo, a data enthusiast with a passion for uncovering insights from data. With a background in the manufacturing and finance industries, I aim to bring a unique perspective to data analytics. Connect with me on <a href="https://www.linkedin.com/in/abednigo/">LinkedIn</a> and follow my work on Medium for more data science related things.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc3f8bd81c55" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>