Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create double layout and axis for n firms #25

Merged
merged 3 commits into from
Feb 25, 2025
Merged
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 modified output/fig/mean_growth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed output/fig/n_firms.png
Binary file not shown.
Binary file added output/fig/n_firms_cat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed output/fig/n_new_firms.png
Binary file not shown.
Binary file added output/fig/n_new_firms_cat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified output/fig/survival.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 21 additions & 2 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,15 @@ function panel(df::AbstractDataFrame)
@replace gdp = gdp / ppi22
@replace Export = Export / ppi22
@replace Export = 0 @if ismissing(Export)
@egen max_emp_5 = maximum(cond(firmage <= 5, emp, 0)), by(frame_id_numeric)
@generate growth = emp / max_emp_5
@egen first_balance = minimum(year), by(frame_id_numeric)
@generate age_in_balance = year - first_balance + 1
@egen max_emp_5 = maximum(cond(age_in_balance <= 5, emp, 0)), by(frame_id_numeric)
@generate growth = emp / max_emp_5
@generate category_old = category
@replace category = size_category(max_emp_5) * " domestic"
@replace category = "small domestic" @if category == "micro domestic"
@egen ever_foreign = maximum(fo3), by(frame_id_numeric)
@replace category = "foreign" @if ever_foreign == 1
@collapse mean_growth = mean(growth) n_firms = rowcount(distinct(frame_id_numeric)), by(category, age_in_balance)
@egen max_n = maximum(cond(age_in_balance == 1, n_firms, 0)), by(category)
@generate survival = 100 * n_firms / max_n
Expand Down Expand Up @@ -177,3 +182,17 @@ function histogram(df::AbstractDataFrame, y::Symbol, weight::Symbol = :n_ceos)
fig = draw(plot; axis = axis)
save("$(figure_folder)/$(y).png", fig, px_per_unit = 1)
end

function ts_plot_dy(df::AbstractDataFrame, y::Symbol, t::Symbol = :year, ytickformatvar::String = :"{:.0f}", xticksvar::StepRange = :1980:2:2022)
axis = (width = 1000, height = 600,
ytickformat = ytickformatvar,
xtickwidth = 1,
xminorticksvisible = true,
xminorgridvisible = true,
xgridvisible = true,
xtickformat = "{:.0f}",
xticks = xticksvar)
layer_1 = data(df) * mapping(t, y, color = :category, layout = :category_2) * visual(Lines, linewidth = 4)
fig = draw(layer_1; axis = axis, facet = (; linkxaxes = :none, linkyaxes = :none))
save("$(figure_folder)/$(y).png", fig, px_per_unit = 1)
end
12 changes: 10 additions & 2 deletions src/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ function main()
@keep @if year <= 2017
@generate exporter_share = n_firms_export / n_firms
end
bycat = @with all begin
@generate category_1 = category
@replace category_1 = "" @if (category_1 == "micro domestic")
@generate category_2 = ""
@replace category_2 = category @if (category == "micro domestic")
@collapse n_firms_cat = sum(n_firms) n_new_firms_cat = sum(n_new_firms), by(year, category, category_1, category_2)
@sort year category category_1 category_2
end

set_aog_theme!()

fig1 = ts_plot(all, :n_firms)
fig1 = ts_plot_dy(bycat, :n_firms_cat)
fig2 = ts_plot(bysize, :sales_per_worker)
fig3 = ts_plot(bysize, :gdp_per_worker)
fig4 = ts_plot((@with bysize @keep @if year <= 2017), :export_share, :year, "{:.1f}")
fig5 = ts_plot(exporters, :exporter_share, :year, "{:.1f}")
fig6 = ts_plot(all, :n_new_firms)
fig6 = ts_plot_dy(bycat, :n_new_firms_cat)
fig7 = ts_plot(survival, :survival, :age_in_balance, "{:.0f}", 0:5:40)
fig8 = ts_plot(survival, :mean_growth, :age_in_balance, "{:.0f}", 0:5:40)
fig9 = ts_plot((@with byceo @keep @if year >= 2013), :mean_age)
Expand Down