How to install STATA


STATA Kernel density function PSLM

Try to use the following command, if you have ‘wage’ variable that take income and gender variable ‘sbq04’ otherwise, change the names as per your data sets.

. kdensity wage, nograph generate(x fx)
. kdensity wage if sbq04==1, nograph generate(fx0) at(x)
. kdensity wage if sbq04==2, nograph generate(fx1) at(x)
. label var fx0 “Male”
. label var fx1 “Female”
. line fx0 fx1 x, sort ytitle(Density)

PSLM STATA – How to calcuate education of household head

Asalaam o Alaikum,

To calculate education of household head in a new variable lets say – hhedu

. egen hhedu = total(( s1aq02 == 1) * s2bq05) , by( hhcode)

/* I use PSLM 2011-12 data/variable names */

Create a new variable hhedu which stores information for each household member about his/her household head education.

. egen hhedu = total(( s1aq02 == 1) * s2bq05) , by( hhcode)

This command can ne edited to capture information about age of household head, income of household head etc. Your just need to replace s2bq05 with age variable or income variable.

Hope it helps.

PSLM STATA – How to calculate number of child less than 5 years

Asalam o Alikum,

As you know, Pakistan Social and Living Measure (PSLM) has published data set for 2014-15, which is available online at FBS website, its need emerges even more.

Today, I am going to share the method for calculating a variable which will be calculated after counting number of children in each family who are under 5 years age.

In SATA just type command

. egen nchild5=total (age<=5), by ( hhcode )

egen will generate a new variable
gives it value of total number of children who are less than 5 years, and give this value with in each house hold.

Good luck

PSLM – How to calculate household size


Go to Aggregate in Data
Click household size (HHcode) as break variable , click number of cases , click ok


If each row/observation in your data is a household. Find a variable that is always present if there is a household member and always missing if there is no household member, such as gender, and use the egen command with a function to count the non-missing values of that variable:

egen hhsize=rownomiss(gender1-gender20)

If instead each observation is a person in the household, then you can use egen with the count function by the household identifier to do the same thing:

bysort hhid: egen hhsize=count(gender)

This second application of egen (using “by”) will put the same value of hhsize on each member of the household.