Advertisement
Guest User

Untitled

a guest
May 10th, 2019
566
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1.  
  2. library(truncnorm)
  3. library(ggplot2)
  4. n <- 100000
  5. t <- 100
  6. a <- 50
  7. unprofit2 <- matrix(nrow = a, ncol = t)
  8. cnt <- matrix(ncol = t)
  9. ##n is the number of firms
  10. while (t > 0) {
  11. pm$"profit" <- matrix(rgamma(n, shape = 2.78, rate = 20.29))
  12. ##creates gamma distribution for profit rates
  13. Inorm <- rtruncnorm(n, a = 0, mean = 11.2, sd = 12.4)
  14. ##creates truncated normal distribution of capital intensity
  15. pm$"CI" <- (.454/pm$"profit") * Inorm
  16. ##derives capital instensity from profit rate and the distribution function
  17. ##see paper "Labour Values, Prices of Production...Germany"
  18. ## https://www.tu-chemnitz.de/wirtschaft/vwl2/downloads/paper/froehlich/deviation.pdf
  19. pm$"Ptotal" <- (pm$"CI"+1)*pm$"profit"
  20. ##multiply capital intensity times profit to get total profit where w = 1
  21. rwg <- c(1:a)
  22. rwg <- rwg/1000
  23. rn <- a
  24. ##real wage growth test cases
  25. unprofit <- matrix(nrow = rn)
  26. unprofit1 <- matrix(ncol = rn, nrow = n)
  27. unprofit[1:rn,] <- 0
  28. ##creates matrix for unprofitable firms
  29. while (rn > 0)
  30. ##loop for every test case
  31. {unprofit1[,rn] <- pm$"Ptotal" - rwg[rn];
  32. ##fills matrix column with new profit rates after a given raise in real wages
  33. for (val in unprofit1[,rn]) {
  34. if (val <= 0) {unprofit[rn,] <- unprofit[rn,] + 1}};
  35. ##checks how many profit rates are now zero or lower
  36. rn <- rn - 1;}
  37. ##moves to next test case
  38. unprofit2[,t] <- unprofit
  39. pm$"total" <- pm$"Ptotal" + pm$"CI"
  40. pm$"pt1" <- pm$"Ptotal"
  41. totals <- sum(pm$"total") * .0135
  42. random <- c(1:500)
  43. sample(1:n, 1)
  44. while (totals > 0) {
  45. s <- sample(1:n, 1);
  46. r <- sample(random, 1)/1000;
  47. d <- pm$"pt1"[s]
  48. pm$"pt1"[s] <- pm$"pt1"[s] - r;
  49. if (pm$"pt1"[s] < 0 ) {totals <- totals - d;
  50. pm$"pt1"[s] <- 0
  51. } else {totals <- totals - d}
  52. }
  53. cn <- 0
  54. for (v in pm$"pt1")
  55. {if (v <= 0) {cn <- cn + 1}}
  56. cnt[,t] <- cn
  57. print(t)
  58. t <- t - 1
  59. }
  60. j <- a
  61. while (j > 0) {
  62. unprofit[j,] <- mean(unprofit2[j,]);
  63. j <- j - 1
  64. }
  65. unprofit <- (unprofit/n) * 100
  66. unprofit[35,]
  67. unprofit[40,]
  68. mean(cnt)/n
  69. u35 <- matrix(nrow = a)
  70. u35[1:a,] <- unprofit[35,]
  71. u40 <- matrix(nrow = a)
  72. u40[1:a,] <- unprofit[40,]
  73. ucn <- matrix(nrow = a)
  74. ucn[1:a,] <- mean(cnt)/n
  75. ucn <- ucn +u35
  76. ##turns number unprofitable into percent of firms
  77. plot(rwg, unprofit, type = "l", xlab = "wage growth", ylab = "% firms unprofitable"
  78. )
  79. lines(rwg, u35, type = "l", col = "blue")
  80. lines(rwg, u40, type = "l", col = "red")
  81. lines(rwg, ucn, type = "l", col = "green")
  82. legend(.001, .0095, legend=c("correlation", "critical threshold", "current level", "current level + trade war shock"),
  83. col=c("black", "red", "blue", "green"), lty=1:2, cex=0.8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement