I am making a lot of news report with putdocx command in Stata.
I will collect various news from branches of my company, and I already have distributed the excel sheet that staff in branches will write something.
The form is like below:
Code:
clear set obs 3 gen TITLE = "" gen BODY1 = "" gen BODY2 = "" gen BODY3 = "" replace TITLE = "Title1" in 1 replace TITLE = "Title2" in 2 replace TITLE = "Title3" in 3 replace BODY1 = "This is body1..." in 1 replace BODY1 = "This is body1..." in 2 replace BODY1 = "This is body1..." in 3 replace BODY2 = "This is body2..." in 1 replace BODY2 = "This is body2..." in 3 replace BODY3 = "This is body3..." in 3
Code:
putdocx clear putdocx begin putdocx paragraph, style(Title) putdocx text ("Report of something") levelsof TITLE, local(tlist) foreach t of local tlist { preserve keep if TITLE == "`t'" putdocx paragraph, style(Heading1) putdocx text ("`t'") putdocx paragraph putdocx text (BODY1) putdocx paragraph putdocx text (BODY2) putdocx paragraph putdocx text (BODY3) restore } putdocx save "news_sample.docx", replace
The problem is blank lines that is made from my converting code from xlsx to docx above.
When I open the result docx file, the blank line is located under the news that have just 1 of 2 bodies.
I want to remove that blank lines, so I think "if command" can help me, but I don't know how to use this.
IF a news don't have second or third body, my code don't need to run "putdocx text (BODY2) or (BODY3)".
It is not a major error, but I want to make a well designed report.
Thank you in advance!
0 Response to [putdocx] Using if command to remove blank line
Post a Comment