Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with creating a table showing gender-wise Worker Population Ratio and Unemployment Rates for rural and urban sectors.

    Hello folks! I am working with a dataset that looks something like the following:

    Code:
    * Example generated by -dataex-. For more info, type help    dataex
    clear
    input float sex byte sector float(emp unemp labforce)
    1 1 1 0 1
    1 1 1 0 1
    2 1 1 0 1
    2 1 1 0 1
    1 1 1 0 1
    1 1 1 0 1
    1 1 1 0 1
    2 1 1 0 1
    1 1 1 0 1
    1 1 0 0 0
    end
    label values sex sex
    label def sex 1 "Male", modify
    label def sex 2 "Female", modify
    label values sector sector
    label def sector 1 "Rural", modify
    So basically I have five observations (sex, sector, emp, unemp, labforce).

    I want to create a table that looks something like the following:
    Click image for larger version

Name:	Capture1.PNG
Views:	2
Size:	43.4 KB
ID:	1758084



    I am not able to figure out how I calculate WPR (Worker Population Ratio) and UR (Unemployment Rate) in Stata and tabulate that on gender and sector variables.

    Note:
    WPR = No. of Employed (emp) / Working age population
    UR = No. of Unemployed (unemp) / (No. of Employed + No. of Unemployed)

    Since I am new to Stata, I will appreciate a lot if you could add brief explanatory comments to your codes. Thanks!
    Last edited by Tokir Alam; 08 Jul 2024, 00:08. Reason: Typo

  • #2
    You don't explain your data completely. How do we know if somebody is of the working age population? Is that what labforce tells us? And your example data contains only Rural, no Urban. Also, in your data, except for the one person who has labforce = 0, everybody is employed. A more representative data set would have been helpful.

    I think you want to do something like this:
    Code:
    * Example generated by -dataex-. For more info, type help    dataex
    clear
    input float sex byte sector float(emp unemp labforce)
    1 1 1 0 1
    1 1 1 0 1
    2 1 1 0 1
    2 1 1 0 1
    1 1 1 0 1
    1 1 1 0 1
    1 1 1 0 1
    2 1 1 0 1
    1 1 1 0 1
    1 1 0 0 0
    end
    label values sex sex
    label def sex 1 "Male", modify
    label def sex 2 "Female", modify
    label values sector sector
    label def sector 1 "Rural", modify
    
    assert !missing(emp, unemp)
    assert !(emp & unemp)
    assert labforce == emp | unemp
    
    keep if labforce
    
    preserve
    collapse (mean) emp, by(sector)
    tempfile by_sector
    save `by_sector'
    
    restore, preserve
    collapse (mean) emp, by(sex)
    tempfile by_sex
    save `by_sex'
    
    restore, preserve
    collapse (mean) emp, by(sex sector)
    tempfile by_sex_sector
    save `by_sex_sector'
    
    restore
    collapse (mean) emp
    append using `by_sector' `by_sex' `by_sex_sector'
    
    gen wpr = 100 * emp
    gen ur = 100 - wpr
    
    label define sex 0 "Pers", add
    mvencode sex, mv(0)
    
    label define sector 0 "Rural+Urban", add
    mvencode sector, mv(0)
    
    table (var) (sector sex), statistic(first ur wpr)
    Note: If your data are interpretable in the way that I have assumed they are when writing this code, the three -assert- commands at the beginning will produce no output. Only run the rest of the code if that is what happens. If any of the assert statements leads to an error message, do not attempt to execute the rest of the code as it will, at best, produce garbage.

    Comment


    • #3
      Hello Dr. Clyde! Thanks for taking time to answer my question. Your code is working fine. And I apologize for ambiguity in my explanation of the dataset. I agree that I have presented a subset that is not very representative of the original data. Actually, the sector variable does have observations for both rural and urban. I should have taken a larger subset.

      Comment

      Working...
      X