# print string vectors with numeric vectors

I have the following procedure

``````N_Theta = 10;
N_Wage = 30;

string gender = {"M" "W"};
string educ = {"l" "h"};
string labor_st= {"u" "e"};
string marr_st = {"s" "m"};

//// Initial guess for Value Functions
wage_st=1|N_Wage;
love_st=1|N_theta;
pos_FP=ones(40,1);

wa_lo_FP=ones(40,3);// Cols: wages~love~wages_sp
i=1;
for gen (1,2,1);
for edu (1,2,1);
//i=1;
for marr (1,2,1);

if marr==1;//marr=1;
for labor (1,2,1);
if i==1;
pos_FP[i]=wage_st[labor]*love_st[marr];
wa_lo_FP[i,.]=wage_st[labor]~love_st[marr]~1; i=i+1;
pos_FP_st=gender[gen]\$+"_"\$+marr_st[marr]\$+labor_st[labor]\$+"_"\$+educ[edu];
else;
pos_FP[i]=wage_st[labor]*love_st[marr]+pos_FP[i-1];
wa_lo_FP[i,.]=wage_st[labor]~love_st[marr]~1; i=i+1;
pos_FP_st=pos_FP_st\$|gender[gen]\$+"_"\$+marr_st[marr]\$+labor_st[labor]\$+"_"\$+educ[edu];
endif;

endfor;
endif;

if marr==2;
for labor (1,2,1);
for labor_sp (1,2,1);
for edu_sp (1,2,1);
pos_FP_st=pos_FP_st\$|gender[gen]\$+"_"\$+marr_st[marr]\$+labor_st[labor]\$+labor_st[labor_sp]\$+"_"\$+educ[edu]\$+educ[edu_sp];
pos_FP[i]=wage_st[labor]*wage_st[labor_sp]*love_st[marr]+pos_FP[i-1];
wa_lo_FP[i,.]=wage_st[labor]~love_st[marr]~wage_st[labor_sp]; i=i+1;
endfor;
endfor;
endfor;
endif;

endfor;
endfor;
endfor;

string label_n=pos_FP_st;

mask = { 0 1 1 1 1};

c = label_n~pos_FP~pos_FP~wa_lo_FP;

What should I do to print pos_FP_st with the other numeric vectors, I have tried a normal print but neither way is working.

Thank you.

0

You should use the `sprintf` function.

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

sprintf("%10s %8.4f %8.4f", label, a, b);``````
```     apple   1.0000   9.0000
banana   2.0000  10.0000
canteloupe   3.0000  11.0000```

aptech

1,773

0

Great, it worked.

If I want to export that object to excel or latex, how should I do it?

0

### Excel

You can use `xlsWrite` to write data from GAUSS to an Excel file. However, you might need to write the numeric and string data separately. Something like:

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

fname = "myfile.xlsx";
call xlsWrite(label, fname, "A1");
call xlsWrite(a~b, fname, "B1");``````

### Latex

I'm not sure how you are creating your Latex document, but the "meat" of a table in Latex is usually the data with ampersands as column separators. You could add the ampersands to the `sprintf` call from the earlier post like this:

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

// Send results of next print to 'mytextfile.txt'
// 'reset' means overwrite the file if it already exists
output file=mytextfile.txt reset;

// print the table to the output window and the file
print sprintf("%10s & %8.4f & %8.4f\\\\", label, a, b);

// stop sending printed output to the file
output off;``````
```     apple &   1.0000 &   9.0000\
banana &   2.0000 &  10.0000\
canteloupe &   3.0000 &  11.0000\ ```

aptech

1,773

0

You should use the `sprintf` function.

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

sprintf("%10s %8.4f %8.4f", label, a, b);``````
```     apple   1.0000   9.0000
banana   2.0000  10.0000
canteloupe   3.0000  11.0000```

0

Great, it worked.

If I want to export that object to excel or latex, how should I do it?

0

### Excel

You can use `xlsWrite` to write data from GAUSS to an Excel file. However, you might need to write the numeric and string data separately. Something like:

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

fname = "myfile.xlsx";
call xlsWrite(label, fname, "A1");
call xlsWrite(a~b, fname, "B1");``````

### Latex

I'm not sure how you are creating your Latex document, but the "meat" of a table in Latex is usually the data with ampersands as column separators. You could add the ampersands to the `sprintf` call from the earlier post like this:

``````a = { 1, 2, 3 };
b = { 9, 10, 11 };
label = "apple" \$| "banana" \$| "canteloupe";

// Send results of next print to 'mytextfile.txt'
// 'reset' means overwrite the file if it already exists
output file=mytextfile.txt reset;

// print the table to the output window and the file
print sprintf("%10s & %8.4f & %8.4f\\\\", label, a, b);

// stop sending printed output to the file
output off;``````
```     apple &   1.0000 &   9.0000\
banana &   2.0000 &  10.0000\
canteloupe &   3.0000 &  11.0000\ ```