This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tim Riffe | |
# HT Andrew Noymer | |
# Link to original Schoen article (Demography, 1970): | |
# http://link.springer.com/article/10.2307/2060150 | |
#library(devtools) | |
#install_github("timriffe/TR1/TR1/HMDHFDplus") | |
library(HMDHFDplus) | |
library(data.table) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# fun with GSS data, using ajdamico's code to read in and weight the data | |
# below see code for US male and female subjective wellbeing Lexis surfaces! | |
# sorry you'll need to change all file paths below to work with the data. I | |
# forgot to setwd() while playing | |
# ---------------------------------- | |
# analyze survey data for free (http://asdfree.com) with the r language | |
# general social survey | |
# 1972-2012 cross-sectional cumulative data (release 1, march 2013) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 1) install DemogBerkeley package from github | |
library(devtools) | |
install_github("DemogBerkeley", subdir = "DemogBerkeley", username = "UCBdemography") | |
library(DemogBerkeley) | |
library(parallel) | |
# handy-dandy function to get a vector of the country codes: | |
CNTRIES <- getHMDcountries() | |
# ---------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' | |
#' @title aggN aggregate vector of single age (year) data to N-year groups | |
#' | |
#' @description This only makes sense if N is 5 or 10 (or 2 I guess), since it uses modulo to find groups | |
#' Ages are assumed to start at 0 and count up in single ages. | |
#' | |
#' @param x the vector of single-age-classified data | |
#' @param N desired width of interval, e.g., 5 or 10 | |
#' | |
#' @export |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# author: tim riffe | |
# March 24, 2014 | |
# do with this as you will. If you sell it, I'l hunt you down. | |
# Thanks to Vladimir Canudas Romo for the idea! | |
# -------------------------------------------- | |
# start | |
# This package is under development! please test! | |
# installation is via github. See the README for instructions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Tim Riffe | |
# 30 March, 2014 | |
############################################################################### | |
library(parallel) # used for mclapply() | |
library(sp) # basic spatial utils | |
library(reshape2) # used for acast() | |
library(compiler) # to make some function run faster | |
## if you don't have the DemogBerkeley package: | |
# library(devtools) | |
# install_github("DemogBerkeley", subdir = "DemogBerkeley", username = "UCBdemography") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#library(devtools) | |
#install_github("DemogBerkeley", subdir = "DemogBerkeley", username = "UCBdemography") | |
library(DemogBerkeley) | |
# this will only work if you have an HMD username and password... | |
# but see the rest inc ase you want to try it on some other lifetable | |
username <- userInput() # do these one at a time, enter text into console | |
# this assigns the text to a variable without you | |
# having to save it in the script. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see install instructions here: | |
# https://github.com/UCBdemography/DemogBerkeley | |
library(DemogBerkeley) | |
us <- userInput() | |
pass <- userInput() | |
mltper <- readHMDweb("USA","mltper_1x1",username = us, password = pass) | |
lx <- mltper$lx[mltper$Year == 2010] | |
lx <- lx / 1e5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# download linked data from here: | |
# data from http://www.demog.berkeley.edu/croatia/datadir/Linkfiles/linkfiles.htm | |
# add path to where data is, or set working directory | |
CRO <- read.table("croatdata4.txt.gz", | |
stringsAsFactors = FALSE, sep = "\t", col.names = c('bid','bdate','sex','motherid','fatherid','mid1','mid2','mid3','mid4','mid5', | |
'sid1','sid2','sid3','sid4','sid5','mdate1','mdate2','mdate3','mdate4','mdate5','did', | |
'ddate','idk1','idk2','idk3','idk4','idk5','idk6','idk7','idk8','idk9','idk10','idk11', | |
'idk12','idk13','idk14','dobk1','dobk2','dobk3','dobk4','dobk5','dobk6','dobk7','dobk8','dobk9', | |
'dobk10','dobk11','dobk12','dobk13','dobk14','sidk1','sidk2','sidk3','sidk4','sidk5','sidk6','sidk7', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# written 24 July, 2014 for fun, hope I didn't leave anything out. | |
# If you can get stuff installed, this should run on its own | |
# first part copied from Fischer.R, sonifaction code after | |
# change this as needed: | |
setwd("/home/triffe/git/TimeProposal/TimeLab") | |
# ----------------------------------------------------- | |
# Utility functions. |
OlderNewer