I’m wondering how I can generate a variable that is equal to some value when other variables are equal to specific values. For example, take the panel data generating process below:
panels <- fabricate( countries = add_level(N = 150, country_fe = runif(N, 1, 10)), years = add_level(N = 25, year_shock = runif(N, 1, 10), nest = FALSE), obs = cross_levels( by = join(countries, years), tr = rbinom(N,1,0.5), new_variable = country_fe + year_shock + rnorm(N, 0, 2) ) )
I want to generate a variable “Post” that is equal to 1 when tr == 1 and when years == 25, but is zero otherwise. I can do this after the fabricate call but I was wondering if there is a way to do that within the fabricate call. Thanks.