Announcement

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

  • #16
    I wrote unclearly. It is the pairing of
    Code:
    by country (year), sort: egen all_ww2 = min(cond(inrange(year, 1939, 1945), classification, .))
    by year (country), sort: egen avg_ww2_pit_all = mean(cond(inrange(year, 1937, 1960) & all_ww2, pit, .))
    that does not work the way you want. The variable classification was defined so that the first of these commands codes neutral parties as all_ww2 = 0. In the second command, then, because all_ww2 = 0 for a neutral country, the value of cond(inrange...) is always false, and so it is missing value (.), not pit, that gets fed into the evaluation of the -mean()-. In other words, neutral countries are excluded from the calculation of avg_ww2_pit_all.

    That said, all countries are classified as either neutral, late entry, or belligerent: there is no other value to variable all_ww2. So you don't need a variable to decide which countries are included: all countries are included. So you can just dispense with variable all_ww2, and change the second command to:
    Code:
    by year (country), sort: egen avg_ww2_pit_all = mean(cond(inrange(year, 1937, 1960), pit, .))
    As to the classification of the US in WW2, I see that I made an error in the code for variable classification. The error was that I based the distinction between late entry and belligerent on the number of years of participation being less than 5. That's fine for WW1, which had a 5 year duration. But it's wrong for WW2, which lasted 7 years. Sorry about that. So the fix for this is:
    Code:
    gen byte war = 1 if inrange(year, 1914, 1918)
    replace war = 2 if inrange(year, 1939, 1945)
    gen war_duration = 5 if war == 1
    replace war_duration = 7 if war == 2
    
    by country war (year), sort: gen years_participation = sum(participant != 0)
    by country war (years_participation), sort: gen byte classification:classification = 0 if years_participation[_N] == 0
    by country war (years_participation): replace classification = cond(years_participation[_N] < war_duration, 1, 2) if missing(classification)
    label values classification classification
    label def classification 0 "Neutral", modify
    label def classification 1 "Late Entry", modify
    label def classification 2 "Belligerent", modify

    Comment


    • #17
      Got it, thanks for the explanation!
      As far as I can see, everything is working now. The graphics show a comprehensible result. I can now complete my work.

      Thank you very much for your consistent support, Mr. Schechter.

      Comment


      • #18
        Hello again,

        I would like to take up this topic again. At the moment I am re-structuring my data set to better apply other variables. However, Stata is now giving me the following error:
        ". *WWI
        . by country (year), sort: egen neutral_ww1 = min(cond(inrange(year, 1914, 1918), classification == 0, .))
        . by year (country), sort: egen avg_ww1_pit_neu = mean(cond(inrange(year, 1912, 1933) & neutral_ww1, pit, .))
        type mismatch
        r(109);"

        I don't quite see what doesn't fit together.
        My variables are: year country pit part libdem GDPPC VATP. Likewise here is my code
        Code:
        cd "U:\Dokumente\MA_Thesis"
        use LibDem_Remix.dta
        
        
        //participation during WWI and WWII
        unab prefix : *part 
        local prefix : subinstr local prefix "part" "", all 
        
        foreach p of local prefix { 
        replace `p'_part = 0 if missing(`p'_part)
        }
        
        gen byte war = 1 if inrange(year, 1914, 1918)
        replace war = 2 if inrange(year, 1939, 1945)
        gen war_duration = 5 if war == 1
        replace war_duration = 7 if war == 2
        
        by country war (year), sort: gen years_participation = sum(part != 0)
        by country war (years_participation), sort: gen byte classification:classification = 0 if years_participation[_N] == 0
        by country war (years_participation): replace classification = cond(years_participation[_N] < 5, 1, 2) if missing(classification)
        label values classification classification
        label def classification 0 "Neutral", modify
        label def classification 1 "Late Entry", modify
        label def classification 2 "Belligerent", modify
        
        *WWI
        by country (year), sort: egen neutral_ww1 = min(cond(inrange(year, 1914, 1918), classification == 0, .))
        by year (country), sort: egen avg_ww1_pit_neu = mean(cond(inrange(year, 1912, 1933) & neutral_ww1, pit, .))
        
        by country (year), sort: egen late_ww1 = min(cond(inrange(year, 1914, 1918), classification == 1, .))
        by year (country), sort: egen avg_ww1_pit_late = mean(cond(inrange(year, 1912, 1933) & late_ww1, pit, .))
        
        by country (year), sort: egen belligerent_ww1 = min(cond(inrange(year, 1914, 1918), classification == 2, .))
        by year (country), sort: egen avg_ww1_pit_belligerent = mean(cond(inrange(year, 1912, 1933) & belligerent_ww1, pit, .))
        
        by country (year), sort: egen all_ww1 = min(cond(inrange(year, 1914, 1918), classification, .))
        by year (country), sort: egen avg_ww1_pit_all = mean(cond(inrange(year, 1912, 1933) & all_ww1, pit, .))
        
        
        *WWII
        by country (year), sort: egen neutral_ww2 = min(cond(inrange(year, 1939, 1945), classification == 0, .))
        by year (country), sort: egen avg_ww2_pit_neu = mean(cond(inrange(year, 1936, 1960) & neutral_ww2, pit, .))
        
        by country (year), sort: egen late_ww2 = min(cond(inrange(year, 1939, 1945), classification == 1, .))
        by year (country), sort: egen avg_ww2_pit_late = mean(cond(inrange(year, 1936, 1960) & late_ww2, pit, .))
        
        by country (year), sort: egen belligerent_ww2 = min(cond(inrange(year, 1939, 1945), classification == 2, .))
        by year (country), sort: egen avg_ww2_pit_belligerent = mean(cond(inrange(year, 1936, 1960) & belligerent_ww2, pit, .))
        
        by country (year), sort: egen all_ww2 = min(cond(inrange(year, 1939, 1945), classification, .))
        by year (country), sort: egen avg_ww2_pit_all = mean(cond(inrange(year, 1936, 1960), pit, .))
        
        
        
        ////
        *World War 1
        egen neutral_ww1_LibDem = rowmean(LibDem_*) if classification == 0 && year < 1918


        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input int year str2 country str6 pit byte part int libdem double(GDPPC VATP) byte H int I byte(J K L M N O war) float(war_duration years_participation) byte classification float neutral_ww1
        1830 "AL" "." .   .    . . .    . . . . . . . . .  1 2 0
        1830 "AR" "." .  87    . . .    . . . . . . . . .  1 2 1
        1830 "AT" "." .   . 2230 . .    . . . . . . . . .  1 2 0
        1830 "AU" "." .   . 1352 . . 1830 . . . . . . . .  1 2 0
        1830 "DZ" "." .   .    . . .    . . . . . . . . .  1 2 0
        1831 "AL" "." .   .    . . .    . . . . . . . . .  2 2 0
        1831 "AR" "." .  87    . . .    . . . . . . . . .  2 2 1
        1831 "AT" "." . 201    . . .    . . . . . . . . .  2 2 0
        1831 "AU" "." .   . 1398 . . 1831 . . . . . . . .  2 2 0
        1831 "DZ" "." .   .    . . .    . . . . . . . . .  2 2 0
        1832 "AL" "." .   .    . . .    . . . . . . . . .  3 2 0
        1832 "AR" "." .  87    . . .    . . . . . . . . .  3 2 1
        1832 "AT" "." . 201    . . .    . . . . . . . . .  3 2 0
        1832 "AU" "." .   . 1428 . . 1832 . . . . . . . .  3 2 0
        1832 "DZ" "." .   .    . . .    . . . . . . . . .  3 2 0
        1833 "AL" "." .   .    . . .    . . . . . . . . .  4 2 0
        1833 "AR" "." .  87    . . .    . . . . . . . . .  4 2 1
        1833 "AT" "." . 201    . . .    . . . . . . . . .  4 2 0
        1833 "AU" "." .   . 1435 . . 1833 . . . . . . . .  4 2 0
        1833 "DZ" "." .   .    . . .    . . . . . . . . .  4 2 0
        1834 "AL" "." .   .    . . .    . . . . . . . . .  5 2 0
        1834 "AR" "." .  87    . . .    . . . . . . . . .  5 2 1
        1834 "AT" "." . 201    . . .    . . . . . . . . .  5 2 0
        1834 "AU" "." .   . 1508 . . 1834 . . . . . . . .  5 2 0
        1834 "DZ" "." .   .    . . .    . . . . . . . . .  5 2 0
        1835 "AL" "." .   .    . . .    . . . . . . . . .  6 2 0
        1835 "AR" "." .  87    . . .    . . . . . . . . .  6 2 1
        1835 "AT" "." . 201    . . .    . . . . . . . . .  6 2 0
        1835 "AU" "." .   . 1825 . . 1835 . . . . . . . .  6 2 0
        1835 "DZ" "." .   .    . . .    . . . . . . . . .  6 2 0
        1836 "AL" "." .   .    . . .    . . . . . . . . .  7 2 0
        1836 "AR" "." .  87    . . .    . . . . . . . . .  7 2 1
        1836 "AT" "." . 201    . . .    . . . . . . . . .  7 2 0
        1836 "AU" "." .   . 1793 . . 1836 . . . . . . . .  7 2 0
        1836 "DZ" "." .   .    . . .    . . . . . . . . .  7 2 0
        1837 "AL" "." .   .    . . .    . . . . . . . . .  8 2 0
        1837 "AR" "." .  87    . . .    . . . . . . . . .  8 2 1
        1837 "AT" "." . 201    . . .    . . . . . . . . .  8 2 0
        1837 "AU" "." .   . 1881 . . 1837 . . . . . . . .  8 2 0
        1837 "DZ" "." .   .    . . .    . . . . . . . . .  8 2 0
        1838 "AL" "." .   .    . . .    . . . . . . . . .  9 2 0
        1838 "AR" "." .  87    . . .    . . . . . . . . .  9 2 1
        1838 "AT" "." . 201    . . .    . . . . . . . . .  9 2 0
        1838 "AU" "." .   . 1857 . . 1838 . . . . . . . .  9 2 0
        1838 "DZ" "." .   .    . . .    . . . . . . . . .  9 2 0
        1839 "AL" "." .   .    . . .    . . . . . . . . . 10 2 0
        1839 "AR" "." .  87    . . .    . . . . . . . . . 10 2 1
        1839 "AT" "." . 201    . . .    . . . . . . . . . 10 2 0
        1839 "AU" "." .   . 1733 . . 1839 . . . . . . . . 10 2 0
        1839 "DZ" "." .   .    . . .    . . . . . . . . . 10 2 0
        1840 "AL" "." .   .    . . .    . . . . . . . . . 11 2 0
        1840 "AR" "." .  74    . . .    . . . . . . . . . 11 2 1
        1840 "AT" "." . 201 2415 . .    . . . . . . . . . 11 2 0
        1840 "AU" "." .   . 2190 . . 1840 . . . . . . . . 11 2 0
        1840 "DZ" "." .   .    . . .    . . . . . . . . . 11 2 0
        1841 "AL" "." .   .    . . .    . . . . . . . . . 12 2 0
        1841 "AR" "." .  74    . . .    . . . . . . . . . 12 2 1
        1841 "AT" "." . 234    . . .    . . . . . . . . . 12 2 0
        1841 "AU" "." .   . 1868 . . 1841 . . . . . . . . 12 2 0
        1841 "DZ" "." .   .    . . .    . . . . . . . . . 12 2 0
        1842 "AL" "." .   .    . . .    . . . . . . . . . 13 2 0
        1842 "AR" "." .  74    . . .    . . . . . . . . . 13 2 1
        1842 "AT" "." . 234    . . .    . . . . . . . . . 13 2 0
        1842 "AU" "." .   . 1704 . . 1842 . . . . . . . . 13 2 0
        1842 "DZ" "." .   .    . . .    . . . . . . . . . 13 2 0
        1843 "AL" "." .   .    . . .    . . . . . . . . . 14 2 0
        1843 "AR" "." .  74    . . .    . . . . . . . . . 14 2 1
        1843 "AT" "." . 261    . . .    . . . . . . . . . 14 2 0
        1843 "AU" "." .   . 1975 . . 1843 . . . . . . . . 14 2 0
        1843 "DZ" "." .   .    . . .    . . . . . . . . . 14 2 0
        1844 "AL" "." .   .    . . .    . . . . . . . . . 15 2 0
        1844 "AR" "." .  74    . . .    . . . . . . . . . 15 2 1
        1844 "AT" "." . 282    . . .    . . . . . . . . . 15 2 0
        1844 "AU" "." .   . 2246 . . 1844 . . . . . . . . 15 2 0
        1844 "DZ" "." .   .    . . .    . . . . . . . . . 15 2 0
        1845 "AL" "." .   .    . . .    . . . . . . . . . 16 2 0
        1845 "AR" "." .  74    . . .    . . . . . . . . . 16 2 1
        1845 "AT" "." . 282    . . .    . . . . . . . . . 16 2 0
        1845 "AU" "." .   . 2310 . . 1845 . . . . . . . . 16 2 0
        1845 "DZ" "." .   .    . . .    . . . . . . . . . 16 2 0
        1846 "AL" "." .   .    . . .    . . . . . . . . . 17 2 0
        1846 "AR" "." .  74    . . .    . . . . . . . . . 17 2 1
        1846 "AT" "." . 282    . . .    . . . . . . . . . 17 2 0
        1846 "AU" "." .   . 2554 . . 1846 . . . . . . . . 17 2 0
        1846 "DZ" "." .   .    . . .    . . . . . . . . . 17 2 0
        1847 "AL" "." .   .    . . .    . . . . . . . . . 18 2 0
        1847 "AR" "." .  74    . . .    . . . . . . . . . 18 2 1
        1847 "AT" "." . 282    . . .    . . . . . . . . . 18 2 0
        1847 "AU" "." .   . 2954 . . 1847 . . . . . . . . 18 2 0
        1847 "DZ" "." .   .    . . .    . . . . . . . . . 18 2 0
        1848 "AL" "." .   .    . . .    . . . . . . . . . 19 2 0
        1848 "AR" "." .  74    . . .    . . . . . . . . . 19 2 1
        1848 "AT" "." . 282    . . .    . . . . . . . . . 19 2 0
        1848 "AU" "." .   . 3381 . . 1848 . . . . . . . . 19 2 0
        1848 "DZ" "." .   .    . . .    . . . . . . . . . 19 2 0
        1849 "AL" "." .   .    . . .    . . . . . . . . . 20 2 0
        1849 "AR" "." .  74    . . .    . . . . . . . . . 20 2 1
        1849 "AT" "." . 283    . . .    . . . . . . . . . 20 2 0
        1849 "AU" "." .   . 3339 . . 1849 . . . . . . . . 20 2 0
        1849 "DZ" "." .   .    . . .    . . . . . . . . . 20 2 0
        end
        label values classification classification
        label def classification 2 "Belligerent", modify
        Can someone kindly point out the mistake?

        Comment


        • #19
          pit is a string variable. So, you can't take its mean. If pit should really be numeric, you need to destring it.
          Last edited by Nick Cox; 08 Aug 2024, 04:38.

          Comment

          Working...
          X