Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added A-ReadMe.pdf
Binary file not shown.
Binary file added B-Dagg-Janne-paper.pdf
Binary file not shown.
76 changes: 76 additions & 0 deletions processing-and-analysis/command-files/analysis.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Created by Richard Ball
This version: 2015-09-21
Written for Stata 14--SE, 64-bit, for Windows
*/


*TABLE 1
*(USING COUNTRY-LEVEL DATA)
clear
set more off
use "..\Analysis Data\country-analysis.dta"
list countryname cm_satis inc exp, table clean noobs


*TABLE 2, COLUMN 1
*(USING INDIVIDUAL-LEVEL DATA)
clear
set more off
use "..\Analysis Data\individual-analysis.dta"
regress satis age age2


*TABLE 2, COLUMN 2
*(USING INDIVIDUAL-LEVEL DATA)
clear
set more off
use "..\Analysis Data\individual-analysis.dta"
xi: regress satis age age2 i.country


*FIGURE 1
*(USING COUNTRY-LEVEL DATA)
clear
set more off
use "..\Analysis Data\country-analysis.dta"
scatter cm_satis inc, mlabel(countryname)


*FIGURE 2
*(USING COUNTRY-LEVEL DATA)
clear
set more off
use "..\Analysis Data\country-analysis.dta"
scatter cm_satis exp, mlabel(countryname)


*TEXT ON PAGE 4 OF THE PAPER, STATING THAT,
*WHEN COUNTRY FIXED EFFECTS ARE NOT INCLUDED IN THE REGRESSION,
*ESTIMATED AGE AT MINIMUM SWB IS ABOUT
*47 YEARS AND 9 MONTHS
*(USING INDIVIDUAL-LEVEL DATA)
clear
set more off
use "..\Analysis Data\individual-analysis.dta"
quietly regress satis age age2
scalar define b1=_coef[age]
scalar define b2=_coef[age2]
scalar define ageatminsatis=-b1/(2*b2)
scalar list ageatminsatis


*TEXT ON PAGE 4 OF THE PAPER, STATING THAT,
*WHEN COUNTRY FIXED EFFECTS ARE INCLUDED IN THE REGRESSION,
*THE ESTIMATED AGE AT MINIMUM SWB IS ABOUT
*53 YEARS AND 11 MONTHS
*(USING INDIVIDUAL-LEVEL DATA)
clear
set more off
use "..\Analysis Data\individual-analysis.dta"
quietly xi: regress satis age age2 i.country
scalar define b1=_coef[age]
scalar define b2=_coef[age2]
scalar define ageatminsatis=-b1/(2*b2)
scalar list ageatminsatis

73 changes: 73 additions & 0 deletions processing-and-analysis/command-files/data-appendix.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
Created by Richard Ball
This version: 2015-09-21
Written for Stata 14--SE, 64-bit, for Windows
*/


***********************************
*INDIVIDUAL-LEVEL ANALYSIS DATA
***********************************
clear
set more off
use "..\Analysis Data\individual-analysis.dta"

*NUMBER OF RESPONDENTS IN EACH COUNTRY
tab countryname

*VARIABLE: satis

*Frequency table:
tab satis

*Relative frequency chart:
quietly tab satis, gen(sat_)
graph bar sat_*
drop sat_*

*VARIABLE: age

*Summary statistics:
tabstat age, stat(mean sd min p25 p50 p75 max)

*Histogram:
histogram age, percent



***********************************
*COUNTRY-LEVEL ANALYSIS DATA
***********************************
clear
set more off
use "..\Analysis Data\country-analysis.dta"

*VARIABLE: cm_satis

*Summary statistics:
tabstat cm_satis, stat(mean sd min p25 p50 p75 max)

*Histogram:
histogram cm_satis, percent bin(3)

*VARIABLE: exp

*Summary statistics:
tabstat exp, stat(mean sd min p25 p50 p75 max)

*Histogram:
histogram exp, percent bin(4)


*VARIABLE: inc

*Summary statistics:
tabstat inc, stat(mean sd min p25 p50 p75 max)

*Histogram:
histogram inc, percent bin(4)





96 changes: 96 additions & 0 deletions processing-and-analysis/command-files/import-pew.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
Created by Richard Ball
This version: 2015-09-21
Written for Stata 14--SE, 64-bit, for Windows
*/


clear
set more off

*OPEN THE IMPORTABLE PEW DATA
use "..\Importable Data\importable-pew.dta"

*KEEP ONLY THE VARIABLES THAT WILL BE USED FOR
*THIS STUDY
keep country q2 q74

*GIVE THE VARIABLES NICER NAMES AND LABELS
rename q2 satis
label variable satis "Satisfaction (self-report; scale of 0-10)"

rename q74 age
label variable age "Age (in years)"


*FOR VARIABLES satis AND age
*RECODE "DON'T KNOW" AS "."
*AND RECODE "REFUSED" AS ".a"

/*
To see how missing values and refusals are coded for satis
tab satis
tab satis, nolabel
*/

recode satis 11=. 12=.a

/*
To see how missing values and refusals are coded for age
tab age
tab age, nolabel
*/

recode age 98=. 99=.a


*DROP OBSERVATIONS FOR ALL INDIVIDUALS FOR WHOM
*THE VALUE OF THE VARIABLE satis IS MISSING OR REFUSED
drop if satis>=.

*DROP OBSERVATIONS FOR ALL INDIVIDUALS WHO ARE
*LESS THAN 21 OR MORE THAN 70 YEARS OF AGE
*OR FOR WHOM THE VALUE OF THE VARIABLE age IS MISSING

*To drop observations where the value of age is either
*greater than 70, or missing or refused
drop if age>70

*To drop observations where the value of age is less than 21
drop if age<21


*KEEP DATA ONLY FOR COUNTRIES WITH AT LEAST 900 OBSERVATIONS
*REMAINING IN THE SAMPLE AFTER REMOVAL OF INDIVIDUALS WITH
*MISSING OR REFUSED VALUES OF satis 0R age, AS WELL AS REMOVAL
*OF INDIVIDUALS UNDER 21 OR OVER 70 YEARS OF AGE

*First, generate a variable called country_n that, for each
*individual, equals the total number of observations that remain
*in the sample representing individuals from her/his own country

bysort country: gen country_n=_N

*Then drop all individuals for whom country_n is less than 900
drop if country_n<900

*The variable country_n is no longer needed, so drop it
drop country_n


*FOR THE VARIABLE country, THE VALUE LABEL FOR THE USA (country=40)
*is "us". CHANGE THAT VALUE LABEL TO "US" (just to be consistent with
*value labels for other countries, which are capitalized)
label define COUNTRY 40 US, modify
label value country COUNTRY


*IN SOME OF THE ANALYSIS I WILL WANT TO USE BOTH AGE AND
*THE SQUARE OF AGE. SO GENERATE A NEW VARIABLE age2 EQUAL
*TO THE SQUARE OF AGE.
gen age2=age^2


*SAVE THE MODIFIED DATA SET
*WITH THE NAME pew.dta
save "pew.dta", replace
61 changes: 61 additions & 0 deletions processing-and-analysis/command-files/import-wdi.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@

*test

/*
Created by Richard Ball
This version: 2015-09-21
Written for Stata 14--SE, 64-bit, for Windows
*/


clear
set more off


*IMPORT THE IMPORTABLE PEW DATA
insheet using "..\importable-data\importable-wdi.csv", names


*DROP VARIABLE seriesname BECAUSE IT IS REDUNDANT WITH seriescode
drop seriesname


*THE UNIT OF OBSERVATION IN THE WDI SPREADSHEET
*IS "COUNTRY/SERIES"
*RESHAPE THE SPREADSHEET SO THAT THE UNIT OF OBSERVATION
*IS "COUNTRY" AND EACH VARIABLE IS A SERIES
egen var_no=group(seriescode)
drop seriescode

rename yr2002 var

reshape wide var, i(countrycode) j(var_no)

rename var1 exp
label variable exp "Gov. cons., % of GDP"
rename var2 inc
label variable inc "GDP per capita (current [2002] $ US)"


*SO THAT WE CAN MERGE THIS WDI DATA WITH THE PEW DATA,
*GENERATE A VARIABLE country THAT CODES THE COUNTRIES
*IN THE SAME WAY AS THE PEW DATA.
gen country=8 if countrycode=="CHN"
replace country=17 if countrycode=="IND"
replace country=18 if countrycode=="IDN"
replace country=27 if countrycode=="PAK"
replace country=31 if countrycode=="RUS"
replace country=40 if countrycode=="USA"
replace country=45 if countrycode=="JOR"


*BECAUSE WE HAVE CREATED THE VARIABLE country,
*WE NO LONGER NEED THE VARIABLE countrycode
*SO WE DROP IT
drop countrycode



*SAVE THE MODIFIED DATA SET
*WITH THE NAME WDI.dta
save "wdi.dta", replace
65 changes: 65 additions & 0 deletions processing-and-analysis/command-files/processing.do
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
Created by Richard Ball
This version: 2015-09-21
Written for Stata 14--SE, 64-bit, for Windows
*/


clear
set more off


*OPEN THE IMPORTABLE PEW DATA
use "pew.dta"


*MERGE IN THE WDI DATA
merge m:1 country using "wdi.dta"

/*Check that all the observations matched
when you did the merge

tab _merge
*/

*since the observations all match, drop _merge
drop _merge


*SAVE THE INDIVIDUAL-LEVEL DATA WITH THE NAME individual-analysis.dta
save "..\Analysis Data\individual-analysis.dta", replace


*CREATE A COUNTRY-LEVEL DATA SET
*WITH COUNTRIES IDENTIFIED BY countryname AND country
*INCLUDING THE VARIABLES satis exp AND inc
*IN WHICH

*THE VALUE OF satis IS EQUAL TO THE MEAN VALUE
*FOR ALL INDIVIDUALS IN THE COUNTRY

*THE VALUES OF exp AND inc ARE THE VALUES
*OF THESE VARIABLES FOR THE COUNTRY IN THE YEAR 2002

collapse country satis exp inc, by(countryname)


*CHANGE THE NAME OF THE VARIABLES satis TO cm_satis
*TO INDICATE THAT IN THE COUNTRY-LEVEL
*DATA SET IT REPRESENTS THE COUNTRY MEAN (cm) OF satis
rename satis cm_satis


*GIVE THE VARIABLES NICER LABELS
label variable countryname Country
label variable country "Country ID"
label variable cm_satis "Country Mean Satisfaction"
label variable exp "Gov. cons., % of GDP"
label variable inc "GDP per capita (current [2002] $ US)"


*SAVE THE COUNTRY-LEVEL DATA WITH THE NAME country-analysis.dta
save "..\Analysis Data\country-analysis.dta", replace

erase pew.dta
erase wdi.dta
Binary file added processing-and-analysis/command-files/wdi.dta
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions processing-and-analysis/importable-data/importable-wdi.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Country Name,Country Code,Series Name,Series Code,2002 [YR2002]
India,IND,GDP per capita (current US$),NY.GDP.PCAP.CD,486.640454
India,IND,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,11.89016055
Indonesia,IDN,GDP per capita (current US$),NY.GDP.PCAP.CD,909.8873302
Indonesia,IDN,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,7.257458338
Russian Federation,RUS,GDP per capita (current US$),NY.GDP.PCAP.CD,2375.157871
Russian Federation,RUS,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,17.95363428
Pakistan,PAK,GDP per capita (current US$),NY.GDP.PCAP.CD,483.0318719
Pakistan,PAK,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,8.72392061
China,CHN,GDP per capita (current US$),NY.GDP.PCAP.CD,1135.44795
China,CHN,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,15.59002808
Jordan,JOR,GDP per capita (current US$),NY.GDP.PCAP.CD,1901.580379
Jordan,JOR,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,22.6955729
United States,USA,GDP per capita (current US$),NY.GDP.PCAP.CD,38175.37638
United States,USA,General government final consumption expenditure (% of GDP),NE.CON.GOVT.ZS,15.03979891