Announcement

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

  • Generating country years shares using Eurostat data

    I downloaded data from eurostat using eurostatuse code and want to generate shares of people in education and then want to generate an education index (this second part is straightforward, I can do it)

    The issue is, to create shares, I need a column with totals and I am unable to have the column filled and I have to copy paste the two lines of fill multiple times. How do I create shares of people in secondary and tertiary education grouped by country and year which I can then input to create an education index?

    Code:
            eurostatuse        edat_lfse_03, noflags label long noerase clear
            save            "$Input\\edat_lfse_03.dta", replace
            
            ren                time year
            keep             if sex == "T"
            drop            sex sex_label
            keep             if age == "Y15-64"
    
    *Generate share columns with just share of the population with tertiary education and secondary education (This is where I have a problem) I want separate column with just shares of people in different educ categories
    
            bys                geo year: gen long tert_educ=edat_lfse_03 if isced11_label=="Tertiary education (levels 5-8)"
            bys                geo year: replace tert_educ= tert_educ[_n-1] if missing(tert_educ) //fill in by country and year
            bys                geo year: replace tert_educ= tert_educ[_n+1] if missing(tert_educ)
    
    *calculate education index
    
    bys geo year: gen educ_index = 0.33*(1-sec_educ) + 0.67*(tert_educ)

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str1 freq str6 freq_label str1 sex str7 sex_label str6 age str19 age_label str2 unit str10 unit_label str8 isced11 str87 isced11_label str9 geo str41 geo_label int time double edat_lfse_03
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1992    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1993    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1994    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1995 41.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1996 39.6
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1997 36.6
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1998   36
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                1999 35.3
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2000    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2001    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2002    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2003    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2004 28.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2005 28.2
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2006 29.6
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2007   30
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2008 28.8
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2009   28
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2010   27
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2011 26.6
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2012 25.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2013 25.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2014 23.2
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2015 22.5
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2016 22.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2017 21.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2018 21.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2019 20.5
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2020 20.3
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2021   20
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2022 19.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "AT" "Austria"                2023 19.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1992    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1993    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1994    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1995    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1996    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1997    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1998    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 1999    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2000    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2001    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2002    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2003    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2004    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2005    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2006    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2007    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2008    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2009    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2010    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2011    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2012    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2013    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2014    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2015    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2016    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2017    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2018    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2019    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2020    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2021 28.8
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2022 28.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BA" "Bosnia and Herzegovina" 2023 27.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1992 50.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1993 50.5
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1994 48.8
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1995 47.7
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1996 45.2
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1997   44
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1998 44.3
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                1999 43.5
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2000 41.8
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2001 41.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2002   40
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2003   39
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2004 37.6
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2005 35.9
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2006   35
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2007 34.4
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2008   33
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2009 31.7
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2010 31.7
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2011 30.7
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2012 30.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2013   29
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2014 28.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2015 27.3
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2016 27.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2017   26
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2018 25.1
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2019   24
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2020 23.2
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2021 21.2
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2022 20.5
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BE" "Belgium"                2023 21.3
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BG" "Bulgaria"               1992    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BG" "Bulgaria"               1993    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BG" "Bulgaria"               1994    .
    "A" "Annual" "F" "Females" "Y15-64" "From 15 to 64 years" "PC" "Percentage" "ED0-2" "Less than primary, primary and lower secondary education (levels 0-2)" "BG" "Bulgaria"               1995    .
    end
    Last edited by Lorien Nair; 14 Nov 2024, 08:10.

  • #2
    I'm not sure I understand what you are asking for. But from looking at the code you tried, I think you have a variable, edat_lfse_03, which takes on a unique non-missing value within any group of observations defined by geo and year, but is frequently missing. And you want to spread that non-missing value to all observations in the group. If so, you can do it like this:

    Code:
    by geo year (edat_lfse_03), sort: assert inlist(edat_lfse_03, edat_lfse_03[1], .)
    by geo year (edat_lfse_03): replace edat_lfse_03 = edat_lfse_03[1]
    The first line verifies that there aren't two or more different non-missing values of edat_lfse_03 within any geo year group. The second line copies the non-missing value into every observation of the group.

    If this is not what you want, when posting back, please show an example of what you would want the final result to look like, as well as re-explaining what is needed.

    Added: By the way, there is an error in the code you show. -keep if sex == "T"- leaves no observations in the data. I think you mean -keep if sex == "F"-.

    Comment


    • #3
      Hi Clyde,

      thanks for the feedback.

      I am essentially trying to create a new variable called tert_educ that pulls the tertiary education rate by country and year. My code generates the output in table below under column tert_educ, however I need to enter the following line of code multiple times manually to get that fill:

      The end goal of the using these columns on tert_educ and secondary educ is to run the code easily for generating education index

      Code:
       *Generate share columns with just share of the population with tertiary education and secondary education        
          bys             geo year: gen int tert_educ = edat_lfse_03 if isced11_label == "Tertiary education (levels 5-8)"
              bys             geo year: replace tert_educ = tert_educ[_n-1] if missing(tert_educ)
              bys             geo year: replace tert_educ = tert_educ[_n+1] if missing(tert_educ) //ensure that population variable is sorted and filled correctly
              
              bys             geo year: gen int second_educ = edat_lfse_03 if isced11_label == "Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general"
              bys             geo year: replace second_educ = second_educ[_n-1] if missing(second_educ)
              bys             geo year: replace second_educ = second_educ[_n+1] if missing(second_educ) //ensure that population variable is sorted and filled correctly
              
              bys                geo year: gen educ_index = (1/3)*(1- second_educ ) + (2/3)*( tert_educ )
      Final output
      freq freq_label age age_label unit unit_label isced11 isced11_label geo geo_label year edat_lfse_03 tert_educ educ_index second_educ
      A Annual Y15-64 From 15 to 64 years PC Percentage ED5-8 Tertiary education (levels 5-8) AT Austria 2021 31.8 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED0-2 Less than primary, primary and lower secondary education (levels 0-2) AT Austria 2021 18.5 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4GEN Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general AT Austria 2021 7.3 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4 Upper secondary and post-secondary non-tertiary education (levels 3 and 4) AT Austria 2021 49.8 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4VOC Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - vocational AT Austria 2021 42.4 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3-8 Upper secondary, post-secondary non-tertiary and tertiary education (levels 3-8) AT Austria 2021 81.5 31 18.66667 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED5-8 Tertiary education (levels 5-8) AT Austria 2022 32.5 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4 Upper secondary and post-secondary non-tertiary education (levels 3 and 4) AT Austria 2022 48.8 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED0-2 Less than primary, primary and lower secondary education (levels 0-2) AT Austria 2022 18.6 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4GEN Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general AT Austria 2022 6.9 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4VOC Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - vocational AT Austria 2022 41.9 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3-8 Upper secondary, post-secondary non-tertiary and tertiary education (levels 3-8) AT Austria 2022 81.4 32 19.66667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3-8 Upper secondary, post-secondary non-tertiary and tertiary education (levels 3-8) AT Austria 2023 81.5 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED0-2 Less than primary, primary and lower secondary education (levels 0-2) AT Austria 2023 18.5 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4VOC Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - vocational AT Austria 2023 40.4 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4 Upper secondary and post-secondary non-tertiary education (levels 3 and 4) AT Austria 2023 47.9 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4GEN Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general AT Austria 2023 7.5 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED5-8 Tertiary education (levels 5-8) AT Austria 2023 33.6 33 20 7
      A Annual Y15-64 From 15 to 64 years PC Percentage ED0-2 Less than primary, primary and lower secondary education (levels 0-2) BA Bosnia and Herzegovina 2021 23 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED5-8 Tertiary education (levels 5-8) BA Bosnia and Herzegovina 2021 14.2 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4GEN Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general BA Bosnia and Herzegovina 2021 5.6 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4VOC Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - vocational BA Bosnia and Herzegovina 2021 57.2 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3-8 Upper secondary, post-secondary non-tertiary and tertiary education (levels 3-8) BA Bosnia and Herzegovina 2021 77 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4 Upper secondary and post-secondary non-tertiary education (levels 3 and 4) BA Bosnia and Herzegovina 2021 62.8 14 8 5
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3-8 Upper secondary, post-secondary non-tertiary and tertiary education (levels 3-8) BA Bosnia and Herzegovina 2022 77.1 14 7.666667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4GEN Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - general BA Bosnia and Herzegovina 2022 6.2 14 7.666667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED0-2 Less than primary, primary and lower secondary education (levels 0-2) BA Bosnia and Herzegovina 2022 22.9 14 7.666667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4VOC Upper secondary and post-secondary non-tertiary education (levels 3 and 4) - vocational BA Bosnia and Herzegovina 2022 56.7 14 7.666667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED3_4 Upper secondary and post-secondary non-tertiary education (levels 3 and 4) BA Bosnia and Herzegovina 2022 62.9 14 7.666667 6
      A Annual Y15-64 From 15 to 64 years PC Percentage ED5-8 Tertiary education (levels 5-8) BA Bosnia and Herzegovina 2022 14.2 14 7.666667 6

      Comment


      • #4
        I'm sorry, but I still don't understand what you are trying to do. And I'm afraid I don't understand what the relationship between your desired result and the original data is. In the original data, there is only one observation per geo#year combination. But in the desired result, there are many observations per geo#year combination and I cannot see in the data sets, nor guess from your attempted code, where the data in these additional observations is supposed to come from.

        Comment

        Working...
        X