I am using the following command in Stata 14.2 which has data stacked by industry-year wise. There are 357 industry year groups for the groups 1 to 271 I used the following syntax :
. forval i = 1/271 {
2. capture {
3. winsor cfo_sc if group == `i', gen(work) h(1)
4. replace cfo_sc_w = work if group == `i'
5. drop work
6. }
7. }
This worked fine for winsorizing the data first 271 groups but when I am using the following syntax for winsorizing the remaining groups, I get the winsorised values for group 272 only for other groups I get blank cells. further temporary variable cfo_sc_t created also do not get dropped.:
forval i = 272/357 {
2. capture {
3. winsor2 cfo_sc if group == `i', suffix(_t) cuts(1,99)
4. replace cfo_sc_s = cfo_sc_t if group == `i'
5. drop cfo_sc_t
6. }
7. }
Kindly guide what's wrong in the syntax.
Thank you.
Related Posts with Looping using forvalue in winsor2
Spatial Panel Data TestsHello, I am relatively new to Stata and have been estimating different spatial panels, such as the …
Improving Code SpeedHello Statalist, After much blood sweat and tears I managed to successfully find a working solution…
Conditional drop if command within a certain firm year levelHi, I am working on my master thesis and I am currently busy with the data cleaning process. One of…
Subgroups with coefplot allowing each graph to have its own scale and adjust location of legendDear all I am using the following code to create a graph with 5 plots: Code: coefplot (hba1c1, …
Missing Axis Labels only for some GraphsDear All I am working with a simple panel dataset of 40 individuals' characteristics over 2000 to 2…
Subscribe to:
Post Comments (Atom)
0 Response to Looping using forvalue in winsor2
Post a Comment