<?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 Shravana Kumar Yadav on Medium]]></title>
        <description><![CDATA[Stories by Shravana Kumar Yadav on Medium]]></description>
        <link>https://medium.com/@yadaviitb2018?source=rss-700cb546adc3------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SJoi-2k0Z26teEe5</url>
            <title>Stories by Shravana Kumar Yadav on Medium</title>
            <link>https://medium.com/@yadaviitb2018?source=rss-700cb546adc3------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 04:34:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@yadaviitb2018/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[Working with Periodic Labour Force Survey(PLFS) data in Python (Part 2)]]></title>
            <link>https://medium.com/@yadaviitb2018/working-with-periodic-labour-force-survey-plfs-data-in-python-part-2-f0918c2b3538?source=rss-700cb546adc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0918c2b3538</guid>
            <category><![CDATA[plfs-sample-design]]></category>
            <category><![CDATA[plfs-estimation]]></category>
            <category><![CDATA[plfs-sample-weight]]></category>
            <category><![CDATA[sampling-weight]]></category>
            <category><![CDATA[nss-survey]]></category>
            <dc:creator><![CDATA[Shravana Kumar Yadav]]></dc:creator>
            <pubDate>Sat, 16 Mar 2024 06:21:06 GMT</pubDate>
            <atom:updated>2024-03-16T06:24:33.833Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Part 2. Exploratory Data Analysis(EDA)</strong></h3><p>This article is a continuation of my <a href="https://medium.com/@yadaviitb2018/working-with-periodic-labour-force-survey-plfs-data-in-python-79f8eba134ae">first post</a>(Part1). The first post discussed about downloading the unit level data of PLFS from MoSPI website and converting it into csv for further analysis. In this post I shall be explaining the sample design through data, weight calculation and application of weights in generation of results.</p><p><strong>Sample Design:</strong></p><p>A rotational panel of two-year duration sampling design is used in urban area. Sampling frames for both rural and urban areas remain unchanged for every two-year duration. For detailed explanation of rotation panel scheme refer to MoSPI <a href="https://microdata.gov.in/nada43/index.php/catalog/168">technical document</a>(Instructions to Field Staff PLFS Vol I). I shall discuss more on selection of First Stage Units and Ultimate Stage Units for both Urban and Rural Sample.</p><p>A stratified multi-stage design is adopted where First Stage Units(FSUs) are the Urban Frame Survey (UFS) blocks for urban areas and 2011 Population Census Villages for rural areas whereas Ultimate Stage Units (USUs) are households for both urban and rural areas. In case of large FSUs, one intermediate stage unit, called hamlet group/sub-block, is formed.</p><p>The steps for selecting First Stage Units(FSUs) and Ultimate Sampling Units(USUs) for Urban Sample are outlined in Fig. 2.1 and Fig 2.2 respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*gIdxeBgKv8OA_p8lo54MZA.png" /><figcaption><strong>Fig : 2.1 — Steps for selection of FSUs for Urban Sample.</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*Zk_miZGQqcGZbljh7ijfvw.png" /><figcaption><strong>Fig : 2.2 — Steps for selection of USUs for Urban Sample</strong></figcaption></figure><p>Let us understand the selection of Urban FSUs and USUs by applying necessary filter in already created <strong>final_df_person.csv</strong> file of Households data during Part1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aK4rFgC82Bey_txTF3s6Zg.png" /><figcaption><strong>Table 2.1 : Household level data for Urban Sample</strong></figcaption></figure><p>In the above table, I have filtered the data for a Quarter(Q3)(column D), Sector(2=Urban)(column F), NSS-Region(12)(column I) and Stratum(1)(column J). For this stratum(1), two FSUs(21215 and 24878) are selected, FSU(21215) is taken under Sub-Sample1(column L) and FSU(24878) is taken under Sub-Sample2(column L). Further, Households with FSU(21215) is divided into four second stage strata(SSSs)(Column P) and two households are selected from each Second Stage Stratum(Column Q).</p><p>The steps for selecting First Stage Units(FSUs) and Ultimate Sampling Units(USUs) for the Rural Sample are discussed in Fig. 2.3 and Fig. 2.4 respectively.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*9Vo_NafjmB4aX9O5HnhVig.png" /><figcaption><strong>Fig : 2.3— Steps for selection of USUs for Rural Sample</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*N-3PzrfaASFV1pwQ94r9Vw.png" /><figcaption><strong>Fig : 2.4 — Steps for selection of USUs for Rural Sample</strong></figcaption></figure><p>Let us understand the selection of Rural FSUs and USUs by applying necessary filter in already created csv file of Households data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0lRWjf_rJ4vimKa5vzFCEg.png" /><figcaption><strong>Table 2.2 : Household level data for Rural Sample</strong></figcaption></figure><p>In the above table, I have filtered the data for a Quarter(Q3)(column D), Sector(1=Rural)(column F), NSS-Region(12)(column I) and Sub-Stratum(2)(column K). For this stratum, two FSUs(15589 and 14887) are selected, FSU(15589) is taken under Sub-Sample1(column L) and FSU(14887) is taken under Sub-Sample2(column L). Further, each FSU in sub-samples is divided into hamlet-groups and two groups(1&amp;2)(Column O) are selected. Households within each hamlet-groups is divided into 3 second stage strata(SSSs)(Column P) and one household from SSS1, two households from SSS2 and one household from SSS3 are selected(Column Q).</p><p><strong>Weight Calculation:</strong></p><p>For generating combined estimate for the Calendar Year (taking both the sub-samples together), weights are applied as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*f5lrMd_6yXRuY8RVwpEb_g.png" /></figure><p>Where, MLTS = Weight or multiplier (in two places of decimal) calculated at the level of Second Stage Stratum (SSS) for the Panel. This is calculated based on inclusion probability of the sampling unit. MLTS is inverse of inclusion probability.</p><p>NSS = Number of first stage units(FSUs) surveyed within sector x state x stratum x substratum for any sub-sample in a Second Stage Stratum for the Panel.</p><p>NSC = Number of first stage units(FSUs) surveyed within a sector x state x stratum x substratum for both sub-samples together in a Second Stage Stratum for the Panel.</p><p>Let us understand the Final weight calculation cases from the Households data.</p><p><strong>a) Case : NSS ≠ NSC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WEEax1sNrbB3pbRvbBubMw.png" /><figcaption><strong>Table 2.3 : Household level data for Rural Sample</strong></figcaption></figure><p>In the above table,</p><p>NSS = 1(Column AI), as for Sector(1= Rural)(column F), State(1 = Jammu &amp; Kashmir)(column G), Sub-Stratum(2)(Column K) and Second Stage Stratum(1)(column P), the no of FSUs is one for sub-sample1/sub-sample2(column L), which is 15589/14887.</p><p>NSC = 2(Column AJ), as for Sector(1= Rural)(column F), State(1 = Jammu &amp; Kashmir)(column G), Substratum(2)(Column K) and Second Stage Stratum(1)(column P), the no. of FSUs are two, considering both sub-sample1 and sub-sample2 together(column L), which are 15589 and 14887.</p><p>Hence, Final weight(Column AT) = MLTS(column AK)/200.</p><p><strong>b) Case : NSS = NSC</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*waiSxxTbdQ-0aIeQb2vS-w.png" /><figcaption><strong>Table 2.4 : Households level data for Urban Sample</strong></figcaption></figure><p>From above table,</p><p>NSS = 1(Column AI), as for Sector(2= Urban)(column F), State(18 = Assam)(column G), Stratum(2)(Column J) and Second Stage Stratum(1)(column P), the no of FSU is one for sub-sample1/sub-sample2(column L), which is 24131.</p><p>NSC = 1(Column AJ) as for Sector(2= Urban)(column F), State(18 = Assam)(column G), Stratum(2)(Column J) and Second Stage Stratum(1)(column P), the no of FSU is one, considering both sub-sample1 and sub-sample2 together(column L), which is 24131.</p><p>Hence, Final weight(Column AT) = MLTS(column AK)/100.</p><p><strong>Note:</strong> NSS = NSC occurs when the data is available only for one sub-sample, either sub-sample1 or sub-sample2. This situation arises when collecting data for both sub-samples is not feasible due to certain challenges. In such cases, the entire weight is allocated to the available sub-sample instead of splitting the weight equally between the two.</p><p><strong>Exploratory Data Analysis:</strong></p><p>Exploratory data analysis is an approach to analyze and summarize the main characteristics of the data. As a part of exploratory data analysis, we identify the data gaps, summarize the data at various variables/characteristics and present summary tables in the form of different charts.</p><p><strong>Findings:</strong></p><p>As part of Exploratory Data Analysis (EDA), I have identified five characteristics or parameters of interest. Findings of the analysis are outlined below —</p><ol><li><strong>Estimate of Total number of Households and it’s distribution across Sector(Rural/Urban) : </strong>As mentioned earlier, the Final Weight value corresponds to the number of households represented by the sampled household. Summing the final weight by Sector provide us with estimated total number of households in India across Sector.</li></ol><p>1a) Python Code:</p><pre>import numpy as np<br>import pandas as pd<br>import seaborn as sns<br>import matplotlib.pyplot as plt<br><br>df_hh = pd.read_csv(&quot;final_df_hh.csv&quot;)<br>df_hh[&#39;Sector&#39;] = df_hh[&#39;Sector&#39;].map({1:&#39;Rural&#39;, 2:&#39;Urban&#39;})<br><br>estimated_HHs = df_hh.groupby([&#39;Sector&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Final_Weight&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;}).reset_index()<br>estimated_HHs[&#39;Estimated_Total_HHs&#39;] = estimated_HHs[&#39;Estimated_Total_HHs&#39;].astype(&#39;int64&#39;)<br>estimated_HHs</pre><pre>sns.set_style(&quot;whitegrid&quot;)<br>plt.figure(figsize=(6,6))<br>plt.pie(estimated_HHs[&#39;Estimated_Total_HHs&#39;], labels=estimated_HHs[&#39;Sector&#39;], autopct=&#39;%1.1f%%&#39;)<br>plt.title(&#39;Distribution of Estimated HHs across Sector&#39;)<br>plt.show()</pre><p>1b) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/425/1*UFYc2DWvHhrMquBHmogcOw.png" /><figcaption><strong>Table 2.5 : Distribution of Sampled and Estimated No. of HHs across Sector</strong></figcaption></figure><p>1c) Plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*8RqX7wpf8r5EnBoxurMNeg.png" /><figcaption><strong>Fig 2.5 : Distribution of Estimated HHs across Sector</strong></figcaption></figure><p>1d) Observation: Based on the pie chart above, it’s evident that 69.8% of the estimated households represent rural households, while the remaining 30.2% represent the urban households.</p><p><strong>2. Estimate of Total Population, Average Household Size and it’s distribution across Sector(Rural/Urban): </strong>Multiplying the final weight by the corresponding sampled household size yields the estimated total population represented by the corresponding sampled household, and summing this calculation for all sampled households provides us with estimated population.</p><p>2a) Python code:</p><pre>df_hh[&#39;Estimated_Population&#39;] = df_hh[&#39;Final_Weight&#39;]*df_hh[&#39;Household_Size&#39;]<br>Estimated_Total_Population = int(sum(df_hh[&#39;Estimated_Population&#39;]))<br>Estimated_Total_Population</pre><pre>estimated_HH_size = df_hh.groupby([&#39;Sector&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Household_Size&#39;: sum, &#39;Final_Weight&#39;: sum, &#39;Estimated_Population&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Household_Size&#39;: &#39;Total_Sampled_Population&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;, &#39;Estimated_Population&#39;: &#39;Estimated_Population&#39;}).reset_index()<br>estimated_HH_size[&#39;Avg_HH_Size_Sampled&#39;] = round(estimated_HH_size[&#39;Total_Sampled_Population&#39;]/estimated_HH_size[&#39;Total_Sampled_HHs&#39;],1)<br>estimated_HH_size[&#39;Estimated_Avg_HH_Size&#39;] = round(estimated_HH_size[&#39;Estimated_Population&#39;]/estimated_HH_size[&#39;Estimated_Total_HHs&#39;],1)<br>estimated_HH_size[[&#39;Sector&#39;, &#39;Avg_HH_Size_Sampled&#39;, &#39;Estimated_Avg_HH_Size&#39;]]</pre><p>2b) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/165/1*ZdQNrNl6JIOR8p2zHUNzAw.png" /><figcaption><strong>Total Estimated Population</strong></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*39amZBC0RqMa0dtq7udg2Q.png" /><figcaption><strong>Table 2.6 : Distribution of Sampled and Estimated average HH Size across Sector.</strong></figcaption></figure><p>2c) Observation: From the table above, the total estimated population of India is 1,218,494,302, with an estimated household size of 3.7 for urban areas and 4.4 for rural areas.</p><p><strong>3. Distribution of Estimated number of Households across Household Type of employment : </strong>Summing the final weight across the Type of households for rural and urban populations separately provides us with the estimated total number of households for different types of households in employment.</p><p>A) Rural Households —</p><p>Aa) Python code:</p><pre>rural_hh = df_hh[df_hh[&#39;Sector&#39;] == &#39;Rural&#39;]<br>estimated_HHs_Type = rural_hh.groupby([&#39;HH_type_Desc&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Final_Weight&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;}).reset_index()<br>estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;] = estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;].astype(&#39;int64&#39;)<br>estimated_HHs_Type[&#39;%Total_Sampled_HHs&#39;] = round(100 * estimated_HHs_Type[&#39;Total_Sampled_HHs&#39;] / sum(estimated_HHs_Type[&#39;Total_Sampled_HHs&#39;]),1)<br>estimated_HHs_Type[&#39;%Estimated_Total_HHs&#39;] = round(100 * estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;] / sum(estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;]),1)<br>estimated_HHs_Type</pre><pre>ax = sns.barplot(x = &#39;%Estimated_Total_HHs&#39;, y = &#39;HH_type_Desc&#39;, data = estimated_HHs_Type)<br>ax.bar_label(ax.containers[0])<br>ax.set(xlabel=&#39;% Estimated Rural Housholds&#39;, ylabel=&#39;Type of Households&#39;, title = &#39;Distribution of % Estimated Rural Households across Type&#39; )</pre><p>Ab) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*-kdl_N6_BbFvYN6MVwpeTQ.png" /><figcaption><strong>Table 2.7 : Distribution of Sampled and Estimated Rural Households across Type.</strong></figcaption></figure><p>Ac) Plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*HHuwlfd22hjjpQr76OB0kQ.png" /><figcaption><strong>Fig 2.6 : Distribution of Estimated Rural HHs across Type.</strong></figcaption></figure><p>Ad) Observation: From the bar chart above, it is clear that the majority of rural households (37%) are self-employed in agriculture, followed by 17.5% engaged in casual labor in non-agricultural sectors.</p><p>B. Urban Households —</p><p>Ba) Python code:</p><pre>urban_hh = df_hh[df_hh[&#39;Sector&#39;] == &#39;Urban&#39;]<br>estimated_HHs_Type = urban_hh.groupby([&#39;HH_type_Desc&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Final_Weight&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;}).reset_index()<br>estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;] = estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;].astype(&#39;int64&#39;)<br>estimated_HHs_Type[&#39;%Total_Sampled_HHs&#39;] = round(100 * estimated_HHs_Type[&#39;Total_Sampled_HHs&#39;] / sum(estimated_HHs_Type[&#39;Total_Sampled_HHs&#39;]),1)<br>estimated_HHs_Type[&#39;%Estimated_Total_HHs&#39;] = round(100 * estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;] / sum(estimated_HHs_Type[&#39;Estimated_Total_HHs&#39;]),1)<br>estimated_HHs_Type</pre><pre>ax = sns.barplot(x = &#39;%Estimated_Total_HHs&#39;, y = &#39;HH_type_Desc&#39;, data = estimated_HHs_Type)<br>ax.bar_label(ax.containers[0])<br>ax.set(xlabel=&#39;% Estimated Urban Housholds&#39;, ylabel=&#39;Type of Households&#39;, title = &#39;Distribution of % Estimated Urban Households across Type&#39; )</pre><p>Bb) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*DonbW871tbzjtPB0ECsGvw.png" /><figcaption><strong>Table 2.8 : Distribution of Sampled and Estimated Urban Households across Type.</strong></figcaption></figure><p>Bc) Plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*FGnPhvaVSBzvvlWZP83sMw.png" /><figcaption><strong>Fig 2.7 : Distribution of Estimated Urban HHs across Type.</strong></figcaption></figure><p>Bd) Observation: Unlike rural households, the majority of urban households (42.9%) are engaged in regular wage/salary earning, while 32.3% are self-employed.</p><p><strong>4. Distribution of Estimated number of Households across different Religion :</strong> Summing the final weight of households by religion provides us with the estimated total number of households for different religions.</p><p>4a) Python code:</p><pre>estimated_HHs_religion = df_hh.groupby([&#39;Religion_Desc&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Final_Weight&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;}).reset_index()<br>estimated_HHs_religion[&#39;Estimated_Total_HHs&#39;] = estimated_HHs_religion[&#39;Estimated_Total_HHs&#39;].astype(&#39;int64&#39;)<br>estimated_HHs_religion[&#39;%Total_Sampled_HHs&#39;] = round(100 * estimated_HHs_religion[&#39;Total_Sampled_HHs&#39;] / sum(estimated_HHs_religion[&#39;Total_Sampled_HHs&#39;]),1)<br>estimated_HHs_religion[&#39;%Estimated_Total_HHs&#39;] = round(100 * estimated_HHs_religion[&#39;Estimated_Total_HHs&#39;] / sum(estimated_HHs_religion[&#39;Estimated_Total_HHs&#39;]),1)<br>estimated_HHs_religion</pre><pre>ax = sns.barplot(x = &#39;%Estimated_Total_HHs&#39;, y = &#39;Religion_Desc&#39;, data = estimated_HHs_religion)<br>ax.bar_label(ax.containers[0])<br>ax.set(xlabel=&#39;% Estimated Housholds&#39;, ylabel=&#39;Religion of Households&#39;, title = &#39;Distribution of % Estimated Households across Religion&#39; )</pre><p>4b) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*gOeAiepBxPZthfrZCiN2Ag.png" /><figcaption><strong>Table 2.9 : Distribution of Sampled and Estimated Households across Religion.</strong></figcaption></figure><p>4c) Plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/666/1*fX0hFAUm5gFPHeGCyyCQBA.png" /><figcaption><strong>Fig 2.8 : Distribution of Estimated HHs across Religion.</strong></figcaption></figure><p>4d) Observation: From the bar chart above, the majority of estimated households (79.6%) follow Hinduism, followed by Islam (15.7%) in India.</p><p><strong>5. Distribution of Estimated number of Households across different Social-Group: </strong>Summing the final weight of households by social-group provides us with the estimated total number of households for different social groups.</p><p>5a) Python code:</p><pre>estimated_HHs_socialgroup = df_hh.groupby([&#39;Social Group_Desc&#39;]).agg({&#39;SHNumber&#39;: &#39;count&#39;, &#39;Final_Weight&#39;: sum}).rename(columns={&#39;SHNumber&#39;: &#39;Total_Sampled_HHs&#39;, &#39;Final_Weight&#39;: &#39;Estimated_Total_HHs&#39;}).reset_index()<br>estimated_HHs_socialgroup[&#39;Estimated_Total_HHs&#39;] = estimated_HHs_socialgroup[&#39;Estimated_Total_HHs&#39;].astype(&#39;int64&#39;)<br>estimated_HHs_socialgroup[&#39;%Total_Sampled_HHs&#39;] = round(100 * estimated_HHs_socialgroup[&#39;Total_Sampled_HHs&#39;] / sum(estimated_HHs_socialgroup[&#39;Total_Sampled_HHs&#39;]),1)<br>estimated_HHs_socialgroup[&#39;%Estimated_Total_HHs&#39;] = round(100 * estimated_HHs_socialgroup[&#39;Estimated_Total_HHs&#39;] / sum(estimated_HHs_socialgroup[&#39;Estimated_Total_HHs&#39;]),1)<br>estimated_HHs_socialgroup</pre><pre>ax = sns.barplot(x = &#39;%Estimated_Total_HHs&#39;, y = &#39;Social Group_Desc&#39;, data = estimated_HHs_socialgroup)<br>ax.bar_label(ax.containers[0])<br>ax.set(xlabel=&#39;% Estimated Households&#39;, ylabel=&#39;Social Group of Households&#39;, title = &#39;Distribution of % Estimated Households across Social Group&#39; )</pre><p>5b) Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/779/1*7o0r4rVKXR4kk4zWC_HAYQ.png" /><figcaption><strong>Table 2.10 : Distribution of Sampled and Estimated Households across Social Group.</strong></figcaption></figure><p>5c) Plot:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/690/1*STtVgXURE2XnoRBO5EzN_g.png" /><figcaption><strong>Fig 2.9 : Distribution of Estimated HHs across Social Group.</strong></figcaption></figure><p>5d) Observation: From the bar graph above, it is evident that 42.9% of estimated households belong to the Other Backward Classes (OBC), 18.8% belong to the Scheduled Castes (SC), and 8.7% belong to the Scheduled Tribes (ST) social groups.</p><p>Similarly, we can define population parameters based on our own interest for analysis and provide population parameter estimates using the weight concept discussed above.</p><p>Most of the surveys conducted by NSSO, MoSPI, have a similar sampling design at a high level. Hence, this article can be utilized in a general way for all the National Sample Surveys conducted by MoSPI.</p><p><strong>Thank you for reading!!</strong></p><p>I hope this article has helped you understand PLFS sample design, weight calculation and application of weight for population parameter estimation. If you have any thoughts, questions or feedback, please feel free to leave a comment below. Your comments and suggestions are highly valued and welcomed. <strong>Looking forward to your comments and suggestions✌️</strong></p><p><strong>References:</strong></p><ol><li>Micro level PLFS data — <a href="https://microdata.gov.in/nada43/index.php/catalog/168">https://microdata.gov.in/nada43/index.php/catalog/168</a></li><li>Instructions to Field Staff_PLFS_Vol I — <a href="https://microdata.gov.in/nada43/index.php/catalog/168/download/2114">https://microdata.gov.in/nada43/index.php/catalog/168/download/2114</a></li><li>PLFS annual report [JULY 2021 — JUNE 2022] — <a href="https://mospi.gov.in/sites/default/files/press_release//Press_note_AR_PLFS_2021_22_24022023.pdf">https://mospi.gov.in/sites/default/files/press_release//Press_note_AR_PLFS_2021_22_24022023.pdf</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0918c2b3538" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Periodic Labour Force Survey(PLFS) data in Python]]></title>
            <link>https://medium.com/@yadaviitb2018/working-with-periodic-labour-force-survey-plfs-data-in-python-79f8eba134ae?source=rss-700cb546adc3------2</link>
            <guid isPermaLink="false">https://medium.com/p/79f8eba134ae</guid>
            <dc:creator><![CDATA[Shravana Kumar Yadav]]></dc:creator>
            <pubDate>Sat, 16 Sep 2023 10:22:47 GMT</pubDate>
            <atom:updated>2023-09-18T08:13:40.225Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Working with Periodic Labour Force Survey(PLFS) data in Python (Part 1)</strong></h3><h3><strong>Part 1 : Data Preparation and Validation</strong></h3><p>In this post, I will walk you through steps to download PLFS micro level data, from Ministry of Statistics and Program Implementation(MoSPI) website, which is in <strong>.txt format,</strong> and convert text format data into <strong>.csv format</strong> with fields description using Python programming language.</p><p>Considering the importance of availability of labour force data at more frequent time intervals, National Sample Survey Office (NSSO) launched Periodic Labour Force Survey (PLFS) in April 2017. On the basis of PLFS, estimates of labour force indicators, such as, Labour Force Participation Rate (LFPR), Worker Population Ratio (WPR), Unemployment Rate (UR), distribution of workers by broad status in employment and industry of work in the Current Weekly Status (CWS) are generated quarterly for the urban areas and annually for both urban and rural.</p><h4><strong>1. Getting the Micro Level Data</strong></h4><p>The micro level data of PLFS January 2022 to December 2022 can be accessed through this <a href="https://microdata.gov.in/nada43/index.php/catalog/168">link.</a> Click on <strong><em>GET MICRODATA</em></strong> tab, register yourself and fill out the necessary paper work to download the data. After completing the access process, we will be able to download the file in .zip format and get two files (CHHV1 and CPERV1) on extracting it. The household wise record for visit-1 is stored in CHHV1 data file and Person wise record for visit-1 is stored in CPERV1 data file for all four quarters.</p><p>To convert these text format data files into structured format, we should refer to technical documents. Under <strong><em>DOCUMENTATION</em></strong> <a href="https://microdata.gov.in/nada43/index.php/catalog/168/related_materials">tab</a>, we get the following important technical documents —</p><ul><li><strong>Instructions to Field Staff PLFS Vol I : </strong>This file contains the information related to coverage, concepts, design and definitions used in the survey. Also contains guidelines for listing households and definitions and formulae used to calculate labour force indicators.</li><li><strong>Schedule10.4 FIRST VISIT : </strong>This file contains the list of all the questions, which are divided into blocks, being asked by the surveyor to collect data related to members of household. As the data is collected in numeric form, this file also contains the description of all the levels.</li><li><strong>Data Layout PLFS 2022 : </strong>The main data<strong> </strong>CHHV1.txt and CPERV1.txt are in text format without column names and delimiters among the columns. This file will help us to get all column names with description, block of the schedule and Byte position i.e. start and end position of each column. This file is most important and widely used to convert the text format data into structured format.</li><li><strong>README : </strong>The detailed instructions to access the .txt files, data description files, and sub-sample wise weights/multipliers are given in this file.</li></ul><p>Next, we’ll read the text files and do the necessary data processing to get the desired output using Python</p><h4>2. Data Processing using Python</h4><p>Import the necessary libraries to read the data files in python.</p><p>Here, we have used two python libraries NumPy and Pandas.</p><pre>import numpy as np<br>import pandas as pd</pre><ul><li><strong>Household wise data</strong></li></ul><p>First, we will create a csv file for household wise dataset.</p><p>Read the CHHV1.txt and name it as ‘df_hh’.</p><pre>df_hh = pd.read_fwf(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\CHHV1.txt&#39;, header=None)<br>df_hh.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/775/1*f2tX4h2SIvudabqGVnxUkA.png" /><figcaption>First 5 rows of household wise data</figcaption></figure><p>Next, create the columns with description using fixed width splitting. The details for column and fixed width byte position are given in the data layout file discussed above.</p><pre>col_specification = [(0,2),(2,7),(7,10),(10,12),(12,14),(14,15),(15,17),(17,19),(19,22),(22,24),(24,26),(26,27),(27,31),(31,36),<br>                    (36,37),(37,38),(38,40),(40,42),(42,43),(43,44),(44,45),(45,47),(47,48),(48,49),(49,50),(50,58),(58,66),<br>                    (66,74),(74,82),(82,90),(90,98),(98,100),(100,108),(108,112),(112,115),(115,118),(118,128)]<br><br>col_names = [&#39;Panel&#39;,&#39;File_Identification&#39;,&#39;Schdule&#39;,&#39;Quarter&#39;,&#39;Visit&#39;,&#39;Sector&#39;,&#39;State/Ut_Code&#39;,&#39;District_Code&#39;,&#39;NSS-Region&#39;,<br>            &#39;Stratum&#39;,&#39;Sub-Stratum&#39;,&#39;Sub-Sample&#39;,&#39;Fod_Sub-Region&#39;,&#39;FSU&#39;,&#39;Sample_Sg/Sb_No&#39;,&#39;SSStratum_No&#39;,&#39;SHNumber&#39;,&#39;Month_of_Survey&#39;,<br>            &#39;Response_Code&#39;,&#39;Survey_Code&#39;,&#39;ReasonSubstitutionOrigHH&#39;,&#39;Household_Size&#39;,&#39;Household_Type&#39;,&#39;Religion&#39;,&#39;Social Group&#39;,&#39;HH_consumer_Expenditure_Month_purposes_out_GoodsnServicesRs&#39;,<br>            &#39;Imputed_value_consumption_month_out_Home_Grown_stockRs&#39;,&#39;Imputed_value_consumption_Month_wages_kindRs&#39;,&#39;HH_Annual_Expenditure_clothingRs&#39;,&#39;HH_Annual_Expenditure_BedsteadRs&#39;,&#39;HH_Consumer_Expenditure_MonthRs&#39;,<br>            &#39;Informant_Serial_no&#39;,&#39;Survey_Date&#39;,&#39;Time_Taken_10.4&#39;,&#39;Ns_count_sector x stratum x substratum x sub-sample&#39;,&#39;Ns_count_sector x stratum x substratum&#39;,<br>            &#39;Sub-sample_Multiplier&#39;]<br><br>df_hh = pd.read_fwf(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\CHHV1.txt&#39;, header=None, colspecs=col_specification, names = col_names)<br>df_hh.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*yPAimUrOehENBB84ZFy8yQ.png" /><figcaption>First 5 rows of household wise dataset with column name</figcaption></figure><p>It’s quite evident from the above table that some of the column values, which are in numeric code/level, has no description in the data. Example State/Ut_code column is having value 28 but there is no description of 28. To fill the void of lack of description for the State/Ut_code column, we will be using the data description provided in the second sheet(‘State code’) of the layout file and map the data with the column to embed the description.</p><pre>state_code = pd.read_excel(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\3 Data_LayoutPLFS_2022.xlsx&#39;, sheet_name=&#39;State code&#39;)<br>state_code.drop(index=state_code.index[0], axis=0, inplace=True)<br>StateUt_Code = pd.Series(state_code[&#39;Unnamed: 1&#39;].values, index=state_code[&#39;State Name &amp; Code used in PLFS 2022&#39;]).to_dict()<br>StateUt_Code</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/283/1*7p1Qv7lM6P1W-Mm2gQFJ2w.png" /><figcaption>State/Ut code description dictionary created from State code data</figcaption></figure><p>Similarly, values/levels description of other columns such as Religion, Social_Group, Month_of_Survey etc. are given in the Schedule 10.4 First Visit and we can create dictionary of values/levels description.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*BWdAhEYyy2d6ZECECRAYGg.png" /><figcaption>Block 1 code descriptions from Schedule10.4 FIRST VISIT file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/575/1*QKXRCPU7yKKxV6h9hbrFQg.png" /><figcaption>Block 3 code descriptions from Schedule10.4 FIRST VISIT file</figcaption></figure><pre>Month_of_Survey = {&#39;1&#39;:&#39;Jan&#39;,&#39;2&#39;:&#39;Feb&#39;,&#39;3&#39;:&#39;Mar&#39;,&#39;4&#39;:&#39;Apr&#39;,&#39;5&#39;:&#39;May&#39;,&#39;6&#39;:&#39;Jun&#39;,&#39;7&#39;:&#39;Jul&#39;,&#39;8&#39;:&#39;Aug&#39;,&#39;9&#39;:&#39;Sep&#39;,&#39;10&#39;:&#39;Oct&#39;,&#39;11&#39;:&#39;Nov&#39;,&#39;12&#39;:&#39;Dec&#39;}<br>Response_Code = {&#39;1&#39;:&#39;co-operative and capable&#39;,&#39;2&#39;:&#39;co-operative but not capable&#39;,&#39;3&#39;:&#39;busy&#39;,&#39;4&#39;:&#39;reluctant&#39;,&#39;9&#39;:&#39;others&#39;}<br>Survey_Code = {&#39;1&#39;:&#39;original&#39;,&#39;2&#39;:&#39;substitute&#39;,&#39;3&#39;:&#39;casualty&#39;}<br>ReasonSubstitutionOrigHH = {&#39;1.0&#39;:&#39;informant busy&#39;,&#39;2.0&#39;:&#39;members away from home&#39;,&#39;3.0&#39;:&#39;informant non-cooperative&#39;,&#39;9.0&#39;:&#39;others&#39;}<br>Religion = {&#39;1&#39;:&#39;Hinduism&#39;,&#39;2&#39;:&#39;Islam&#39;,&#39;3&#39;:&#39;Christianity&#39;,&#39;4&#39;:&#39;Sikhism&#39;,&#39;5&#39;:&#39;Jainism&#39;,&#39;6&#39;:&#39;Buddhism&#39;,&#39;7&#39;:&#39;Zoroastrianism&#39;,&#39;9&#39;:&#39;others&#39;}<br>Social_Group = {&#39;1&#39;:&#39;scheduled tribe&#39;,&#39;2&#39;:&#39;scheduled caste&#39;,&#39;3&#39;:&#39;other backward class&#39;,&#39;9&#39;:&#39;others&#39;}<br>HH_type_rural = {1:&#39;self-employed in: agriculture&#39;,2:&#39;self-employed in: non-agriculture&#39;,3:&#39;regular wage/salary earning&#39;,4:&#39;casual labour in: agriculture&#39;,5:&#39;casual labour in: non-agriculture&#39;,9:&#39;others&#39;}<br>HH_type_urban = {1:&#39;self-employed&#39;,2:&#39;regular wage/salary earning&#39;,3:&#39;casual labour&#39;,9:&#39;others&#39;}</pre><p>Next, map the above created dictionary to the respective columns in the data and create description columns.</p><pre>df_hh[&#39;Month_of_Survey_Desc&#39;] = df_hh[&#39;Month_of_Survey&#39;].astype(str).map(Month_of_Survey)<br>df_hh[&#39;Response_Code_Desc&#39;] = df_hh[&#39;Response_Code&#39;].astype(str).map(Response_Code)<br>df_hh[&#39;Survey_Code_Desc&#39;] = df_hh[&#39;Survey_Code&#39;].astype(str).map(Survey_Code)<br>df_hh[&#39;ReasonSubstitutionOrigHH_Desc&#39;] = df_hh[&#39;ReasonSubstitutionOrigHH&#39;].astype(str).map(ReasonSubstitutionOrigHH)<br>df_hh[&#39;Religion_Desc&#39;] = df_hh[&#39;Religion&#39;].astype(str).map(Religion)<br>df_hh[&#39;Social Group_Desc&#39;] = df_hh[&#39;Social Group&#39;].astype(str).map(Social_Group)<br>df_hh[&#39;State/Ut_Code_Desc&#39;] = df_hh[&#39;State/Ut_Code&#39;].map(StateUt_Code)<br>df_hh[&#39;HH_type_Desc&#39;] = df_hh.apply(lambda x: x[[&#39;Household_Type&#39;]].map(HH_type_rural) if x[&#39;Sector&#39;] == 1 else x[[&#39;Household_Type&#39;]].map(HH_type_urban),axis =1)</pre><p>Now, the final household wise data is</p><pre>df_hh.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*Cj4OrJD4cN-q3DhBm10r2A.png" /><figcaption>First 5 rows of processed household wise data</figcaption></figure><p>Finally, write this data ‘df_hh’ into .csv format.</p><pre>df_hh.to_csv(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\final_df_hh.csv&#39;, index = False)</pre><ul><li><strong>Person wise data</strong></li></ul><p>Now, we will create a csv file for person wise data.</p><p>Read the CPERV1.txt file and name it as ‘df_person’.</p><pre>df_person = pd.read_fwf(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\CPERV1.txt&#39;, header=None)<br>df_person.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*KePucQ4aRZcaUi_9jzyH-Q.png" /><figcaption>First 5 rows of person wise dataset</figcaption></figure><p>As discussed above, create the columns with the description using fixed width splitting and data layout file.</p><pre>col_specification = [(0,2),(2,7),(7,10),(10,12),(12,14),(14,15),(15,17),(17,19),(19,22),(22,24),(24,26),(26,27),(27,31),(31,36),<br>                    (36,37),(37,38),(38,40),(40,42),(42,43),(43,46),(46,48),(48,50),(50,52),(52,55),(55,58),(58,61),(61,71)]<br><br>col_names = [&#39;Panel&#39;,&#39;File_Identification&#39;,&#39;Schdule&#39;,&#39;Quarter&#39;,&#39;Visit&#39;,&#39;Sector&#39;,&#39;State/Ut_Code&#39;,&#39;District_Code&#39;,&#39;NSS-Region&#39;,<br>            &#39;Stratum&#39;,&#39;Sub-Stratum&#39;,&#39;Sub-Sample&#39;,&#39;Fod_Sub-Region&#39;,&#39;FSU&#39;,&#39;Sample_Sg/Sb_No&#39;,&#39;SSStratum_No&#39;,&#39;SHNumber&#39;,&#39;Person_SerialNo&#39;,<br>            &#39;Sex&#39;,&#39;Age&#39;,&#39;GeneralEducaionLevel&#39;,&#39;CWS&#39;,&#39;Industry_Code&#39;,&#39;Occupation_Code&#39;,&#39;Ns_count_sector x stratum x substratum x sub-sample&#39;,&#39;Ns_count_sector x stratum x substratum&#39;,<br>            &#39;Sub-sample_Multiplier&#39;]<br><br>df_person = pd.read_fwf(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\CPERV1.txt&#39;, header=None, colspecs=col_specification, names = col_names)<br>df_person.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/764/1*U47fm_NJ7YCUXST1XZaZ4A.png" /><figcaption>First 5 rows of person wise dataset with column name</figcaption></figure><p>Next, embed value’s description of few columns using description data provided in layout file and Schedule 10.4 First Visit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/645/1*bTAlLiXkJrFqRMmAlAo_yQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*_95oFPzDFczOXwrVPXHWmg.png" /></figure><pre>GeneralEducaionLevel = {&#39;1&#39;:&#39;not literate&#39;,&#39;2&#39;:&#39;literate without formal schooling: EGS/ NFEC/ AEC&#39;,&#39;3&#39;:&#39;TLC&#39;,&#39;4&#39;:&#39;others&#39;,&#39;5&#39;:&#39;literate: below primary&#39;,&#39;6&#39;:&#39;primary&#39;,&#39;7&#39;:&#39;middle&#39;,&#39;8&#39;:&#39;secondary&#39;,&#39;10&#39;:&#39;higher secondary&#39;,&#39;11&#39;:&#39;diploma/certificate course&#39;,&#39;12&#39;:&#39;graduate&#39;,&#39;13&#39;:&#39;postgraduate and above&#39;}<br>CWS ={<br>      11:&#39;worked in h.h. enterprise (self-employed): own account worker&#39;, <br>      31:&#39;worked as regular salaried/ wage employee&#39;,<br>      91:&#39;attended educational institution&#39;, <br>      12:&#39;worked in h.h. enterprise (self-employed): employer&#39;, <br>      93:&#39;attended domestic duties and was also engaged in free collection of goods (vegetables, roots, firewood, cattle feed, etc.), sewing, tailoring, weaving, etc. for household use&#39;, <br>      99:&#39;&#39;, <br>      81:&#39;sought work&#39;, <br>      98:&#39;did not work due to temporary sickness (for casual workers only)&#39;, <br>      97:&#39;others (including begging, prostitution, etc.)&#39;, <br>      21:&#39;worked as helper in h.h. enterprise (unpaid family worker)&#39;, <br>      51:&#39;worked as casual wage labour: in other types of work&#39;, <br>      82:&#39;did not seek but was available for work&#39;, <br>      95:&#39;not able to work due to disability&#39;, <br>      94:&#39;rentiers, pensioners , remittance recipients, etc.&#39;, <br>      92:&#39;attended domestic duties only&#39;, <br>      62:&#39;had work in h.h. enterprise but did not work due to: other reasons&#39;, <br>      72:&#39;had regular salaried/wage employment but did not work due to: other reasons&#39;,<br>      42:&#39;worked as casual wage labour in MGNREG works&#39;, <br>      41:&#39;worked as casual wage labour in public works other than MGNREG works&#39;, <br>      61:&#39;had work in h.h. enterprise but did not work due to: sickness&#39;, <br>      71:&#39;had regular salaried/wage employment but did not work due to: sickness&#39;<br>}<br><br>df_person[&#39;GeneralEducaionLevel_Desc&#39;] = df_person[&#39;GeneralEducaionLevel&#39;].astype(str).map(GeneralEducaionLevel)<br>df_person[&#39;State/Ut_Code_Desc&#39;] = df_person[&#39;State/Ut_Code&#39;].map(StateUt_Code)<br>df_person[&#39;CWS_Desc&#39;] = df_person[&#39;CWS&#39;].map(CWS)<br><br>df_person.head()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/771/1*jqrjvr9Q8VSn22Mj6NRRKw.png" /><figcaption>First 5 rows of processed person wise data</figcaption></figure><p>Finally, write this data ‘df_person’ into .csv format.</p><pre>df_person.to_csv(r&#39;E:\Personal Project\PLFS Analysis\PLFS Jan22-Dec22\final_df_person.csv&#39;,index = False)</pre><h4><strong>3. Data Validation</strong></h4><p>As household wise data is having details on household characteristics (Household_Size, Household_Type, Religion, Social Group etc.) of selected sample household and person wise data is having details of all the members of the same household, we can map these two datasets for one or two sample households to check whether data is correctly processed or not. I did this validation in excel.</p><p>Now that we have created csv files for both household wise and person wise datasets with column names and description. Further, we can produce a series of results under exploratory data analysis using these two processed datasets. I will be publishing results of exploratory data analysis in my upcoming post.</p><p><strong>Thanks for reading!!</strong></p><p>This is my first medium post. I am learning to write, mistakes are inevitable, even when I try my best. Your suggestions/comments are welcome. <strong>Looking forward to your comments and suggestions✌️</strong></p><p><strong>References:</strong></p><ol><li>Micro level PLFS data — <a href="https://microdata.gov.in/nada43/index.php/catalog/168">https://microdata.gov.in/nada43/index.php/catalog/168</a></li><li>PLFS annual report [JULY 2021 — JUNE 2022] — <a href="https://mospi.gov.in/sites/default/files/press_release//Press_note_AR_PLFS_2021_22_24022023.pdf">https://mospi.gov.in/sites/default/files/press_release//Press_note_AR_PLFS_2021_22_24022023.pdf</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79f8eba134ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>