Assume that I have a dataset that provides information at the firm level. Specifically, panel data for firms. Among others, this dataset tells us where each firm is located.
The dataset would look like this:
Code:
input str16 (firm country) year y x treated f1A A 2000 0.681062989 -2 1 f1A A 2001 0.22820143 2 0 f2A A 2000 0.701648435 -2 1 f2A A 2001 0.84680434 -3 0 f3A A 2000 0.037081877 1 1 f3A A 2001 0.243891313 5 0 f1B B 2000 0.279915066 -5 0 f1B B 2001 0.126556879 -1 0 f2B B 2000 0.995729496 5 0 f2B B 2001 0.963814474 -3 0 f1C C 2000 0.314235574 -4 0 f1C C 2001 0.501918528 2 1 f2C C 2000 0.332032269 -3 0 f2C C 2001 0.458030646 -3 1 f3C C 2000 0.4850482 1 0 f3C C 2001 0.963088308 -2 1 f4C C 2000 0.152418162 2 0 f4C C 2001 0.128631643 4 1 end
What I need to do is a code that will utilize a loop to randomly assign treatment status by country-year, run a regression of the form: reg y x treated, and save the beta coefficient and the confidence intervals in each loop. For example, if this loop were to be done 10 times, a file should be generated having 10 rows and 3 columns with beta, lower CI limit, upper CI limit.
I have seen in the forum that a potential code that can randomly create 0-1 values is this: gen wanted = cond(uniform() < 0.5, 0, 1), but such a code is not appropriate here, as the data is at the firm level, and I need the pseudo-random treatment to be at the country-year level.
Thanks in advance.
0 Response to Randomly assigning treatment status by a group of two variables then running a loop of regressions
Post a Comment