Bestand:FinancePctOfUSprofits.png
FinancePctOfUSprofits.png (480 × 320 pixels, bestandsgrootte: 3 kB, MIME-type: image/png)
Dit is een bestand van Wikimedia Commons. Onderstaande beschrijving komt van de beschrijving van het bestand daar. Controleer het gebruik van dit bestand in andere Wikimediaprojecten. |
Beschrijving
BeschrijvingFinancePctOfUSprofits.png |
English: Ratio of Finance to Domestic Industries in Table 6.16 of the National Income and Product Accounts, US Bureau of Economic Analysis. |
Datum | |
Bron | Eigen werk |
Auteur | DavidMCEddy |
How to create this image using R
- NOTE: Wikimedia formatting conflicts with R script
- in that the R "#" comment character is ignored in the display
- USE 'EDIT' to get the R script with comment characters
- (not visible in standard display)
- Table 6.16 of the National Income and Product Accounts,
- US Bureau of Economic Analysis.
- How to download the US Bureau of Economic Analysis
- Table 6.16 and create a plot of finance industry
- profits as a percent of US domestic corporate profits
- using R (www.r-project.org)
- Procedure tested 2012.01.30
- 1. Go to the web interface for the
- National Income and Product Accounts (NIPA)
- of the US Bureau of Economic Analysis
- (http://bea.gov/national/nipaweb).
- Select "List of All NIPA tables".
- From there, select 6.16A, 6.16B, 6.16C, and 6.16D
- in turn. With each one, select "Annual series",
- "Get All Years", and Update.
- Then at the bottom, click "Download All Years (CSV)".
- This should produce local copies of files with names like
- "NIPA Table (1).csv", ..., "NIPA Table (4).csv"
- NOTE: Check to make sure you get annual data,
- because a slight error in following the above process
- can produce quarterly numbers.
- Move or copy these files into a working directory
- for your R session and rename them to the following:
(table6.16.csv <- paste('NIPA6.16', LETTERS[1:4], '.csv', sep=))
- 2. Read the contents of the table
table6.16lines <- lapply(table6.16.csv, readLines)
- Confirm that the first line gives the table numbers:
- 6.16 A, B, C, D
sapply(table6.16lines, '[', 1)
- 3. Get years, Domestic Industries, and Financial:
- rows 5, 7 and 8 in each table.
- Confirm that line 5 starts "Line"
(table6.16data <- lapply(table6.16lines, '[', c(5, 7, 8)))
- NOTE: If line 5 does NOT start "Line", you have the wrong table(s).
get6.16data <- function(x){
x. <- gsub('\"', , x) ys <- strsplit(x., split=',') Names <- sapply(ys[-1], '[', 2) Names[2] <- gsub(' ', , Names[2]) yrs <- lapply(ys, '[', -(1:2)) dat <- lapply(yrs, as.numeric) X <- do.call(rbind, dat) dimnames(X) <- list(c('year', Names), NULL) X
}
- confirm that it works with the first one
get6.16data(table6.16data1)
- Now try all 4
(table6.16Data <- lapply(table6.16data, get6.16data))
- 4. Put them together
str(table6.16AB <- do.call(cbind, table6.16Data[1:2]))
- Identify duplicate years, keep the last
keepAB <- (table6.16AB[1,]<table6.16Data3[1,1])
str(table6.16ABC <- cbind(table6.16AB[, keepAB], table6.16Data3))
keepABC <- (table6.16ABC[1,]<table6.16Data4[1,1]) str(table6.16ABCD <- cbind(table6.16ABC[, keepABC], table6.16Data4))
- 5. transpose, convert to data.frame
str(table6.16 <- as.data.frame(t(table6.16ABCD))) names(table6.16)[2] <- 'DomesticIndustries'
- check years increment one at a time
table(diff(table6.16[,1]))
- 6. Add percent
- table6.16$financePct <- with(table6.16, Financial/DomesticIndustries)
png('finance.png', width=480, height=320, bg="transparent") plot(100*Financial/DomesticIndustries ~ year, table6.16, type='l',
ylim=c(0, 40), xlab=, ylab=, frame.plot=FALSE, col='blue', lwd=3, axes=FALSE)
axis(1, seq(1930, 2010, 20), c(1930, NA, 1970, NA, 2010), cex.axis=1.5) axis(2, seq(0, 40, 10), c(0, NA, 20, NA, 40), las=1, cex.axis=1.5)
- title('Finance as a percent of US Domestic Corporate Profits')
dev.off()
svg('finance.svg', width=4, height=8/3, bg="transparent")
plot(100*Financial/DomesticIndustries ~ year, table6.16, type='l',
ylim=c(0, 40), xlab=, ylab=, frame.plot=FALSE, col='blue', lwd=3, axes=FALSE)
axis(1, seq(1930, 2010, 20), c(1930, NA, 1970, NA, 2010), cex.axis=2) axis(2, seq(0, 40, 10), c(0, NA, 20, NA, 40), las=1, cex.axis=2)
- title('Finance as a percent of US Domestic Corporate Profits')
dev.off()
Licentie
- De gebruiker mag:
- Delen – het werk kopiëren, verspreiden en doorgeven
- Remixen – afgeleide werken maken
- Onder de volgende voorwaarden:
- naamsvermelding – U moet op een gepaste manier aan naamsvermelding doen, een link naar de licentie geven, en aangeven of er wijzigingen in het werk zijn aangebracht. U mag dit op elke redelijke manier doen, maar niet zodanig dat de indruk wordt gewekt dat de licentiegever instemt met uw werk of uw gebruik van zijn werk.
- Gelijk delen – Als u het werk heeft geremixt, veranderd, of erop heeft voortgebouwd, moet u het gewijzigde materiaal verspreiden onder dezelfde licentie als het oorspronkelijke werk, of een daarmee compatibele licentie.
Items getoond in dit bestand
beeldt af
Waarde zonder Wikidata-item
31 jan 2012
Bestandsgeschiedenis
Klik op een datum/tijd om het bestand te zien zoals het destijds was.
Datum/tijd | Miniatuur | Afmetingen | Gebruiker | Opmerking | |
---|---|---|---|---|---|
huidige versie | 2 feb 2012 03:46 | 480 × 320 (3 kB) | DavidMCEddy |
Bestandsgebruik
Dit bestand wordt op de volgende pagina gebruikt: