Dear Statalist community,
I would very much appreciate your help on the following problem that I am struggling with. I am trying to do a nearest neighbour matching within industry-year-clusters with Stata17. Unfortunately, I keep on receiving the following error message: invalid syntax. I posted the code below so that maybe someone could help me finding the coding mistake.
The variable
contains the number of observations per industry (`a')-year (`b') cluster. The variable
is the matching indicator. The goal is to match observations with
with observations with
for all 4 x 9 industry clusters by minimizing the difference in firm size
. Furthermore,
contains _n within a `a'x`b'-cluster.
I am not very experienced in Stata coding so the issue might be very basic. Hopefully. Thanks so much for your precious time.
Thankfully with best regards
Marc
I would very much appreciate your help on the following problem that I am struggling with. I am trying to do a nearest neighbour matching within industry-year-clusters with Stata17. Unfortunately, I keep on receiving the following error message: invalid syntax. I posted the code below so that maybe someone could help me finding the coding mistake.
The variable
Code:
N_`a'_`b'_N
Code:
ceo_power_I
Code:
ceo_power_I ==1
Code:
ceo_power_I ==0
Code:
ta_C
Code:
n1
Code:
gen match_firmyr = . gen match_delta = . gen matched =. local a = 1 while `a' <= 4 { local b = 1 while `b' <= 9 { local c = N_`a'_`b'_N forval i = 1/`c' { if n1 == `i' & N_`a'_`b'_N == `c' & ceo_power_I == 1 { local dist 1000000000^2 forval j = 1/`c' { if n1 == `j' & N_`a'_`b'_N == `c' & ceo_power_I == 0 { local ta_match_1_C = ta_C if n1 == `i' & N_`a'_`b'_N == `c' local ta_match_2_C = ta_C if n1 == `j' & N_`a'_`b'_N == `c' local current_dist (`ta_match_1_C' - `ta_match_2_C')^2 local n_count_D `= _n' if n1 == `j' & N_`a'_`b'_N == `c' if `dist' > `current_dist' { local dist `current_dist' // update smallest distance replace match_firmyr = firmyr_O[`n_count_D'] if n1 == `i' & N_`a'_`b'_N == `c'// write match replace match_delta = `current_dist' if n1 == `i' & N_`a'_`b'_N == `c'// write delta } } } replace matched =1 if n1 == `i' & N_`a'_`b'_N == `c' } } local b = `b' + 1 } local a = `a' + 1 }
I am not very experienced in Stata coding so the issue might be very basic. Hopefully. Thanks so much for your precious time.
Thankfully with best regards
Marc
Comment