Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: right justify numeric vars in outfile


From   tashi lama <[email protected]>
To   <[email protected]>
Subject   st: right justify numeric vars in outfile
Date   Fri, 17 Aug 2012 21:45:26 +0000

Hello all, 
    Outfile has an advanced option to right justify string variables. The default is to left justfiy. Is there a way to right justify the numeric variables? The problem in hand is I will generate a dataset which I will change into some text format. For this particular problem, i used outfile to create .raw file (please see the code below). I wrote a simple do-file to change into html. The problem I encountered is the the strings are left justified(I am happy) but the numbers are also left justified( I am not happy). I might have been able to write some if statement to manually left or right justify the variable if there was a way to identify datatype in my text file(by construction there isn't as I opted for noquote in outfile to use tokenize). Any help or direction will be appreciated. 

txt file  
AB,4,22,3
N,4749,17,3
AMC Spirit,245,22,3334
Buick Century,4816,20,3
Buick Electra,7827,15,4
Buick LeSabre,25,18,334
Buick Opel,4453,26,
Buick Regal,5189,13,13
Buick Riviera,10372,103,3
Buick Skylark,4082,1,3

html

AB               4     22  3 
N                4749  17  3 
AMC Spirit       245   22  3334 
Buick Century    4816  20  3 
Buick Electra    7827  15  4 
Buick LeSabre    25    18  334 
Buick Opel       4453  26  
Buick Regal      5189  13  13 
Buick Riviera    10372 103 3 
Buick Skylark    4082  1   3 
 

Here was my code
file open myfile using myout2.raw, read
file open myfile1 using myout1.html, write replace
file write myfile1 "<Table>" _n
file read myfile line
forvalues i=1/10 {
   file write myfile1 "<TR>" _n
   forvalues j=1(2)7 {
      tokenize "`line'", parse(",")
      file write myfile1 "<TD>" "``j''" "</TD>" _n
   }
   file write myfile1 _n
   file write myfile1 "</TR>" _n
   file read myfile line
}
file write myfile1 "</Table>" _n
file close _all
exit

Thanx, 
Tashi  		 	   		  
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index