TiesdeKok / ipystata

Enables the use of Stata together with Python via Jupyter (IPython) notebooks.
192 stars 68 forks source link

bug if the stata command is too long #18

Closed randomgambit closed 7 years ago

randomgambit commented 8 years ago

Hi Tiesdekok,

If I type a very long command line, the output will be trimmed

%%stata
reg price c.price##c.price c.price##c.price##c.price gear_ratio weight headroom mpg c.price##c.price##c.price##c.gear_ratio foreign 

output is

> #c.price##c.price##c.gear_ratio foreign
note: price omitted because of collinearity
note: price omitted because of collinearity
note: gear_ratio omitted because of collinearity

note the weird > at the top. Any idea how to fix this?

Also, I am unable to find a way to break the stata code into different lines when the code is too long. In stata, one would use /// but this does not work here. Any ideas?

Thanks!!

TiesdeKok commented 8 years ago

I am currently not near my own computer (traveling), I will look into this when I get back.

The reason for the lack of line-breaks is related to the way that Stata Automation sends commands to Stata. It basically sends a command as-if it is entered interactively in the command box of Stata, which is different than the way code in a do-file is executed. This works fine for most stuff but certain features only work when code is executed using the "do-file method" like line breaks and most of the comment methods.

But now that I think about it, I will see if it is possible for me to add some Python code that basically reconstructs code with line-breaks back into "one-line" code. This would re-enable the use of line-breaks and solve the problem.

randomgambit commented 8 years ago

Hi Tias, enjoy your travel :)

Just to be sure: there are two related issues here

In any case, keep up with the good work your package is really amazing and will be even more if you are able to fix these minor issues!

randomgambit commented 8 years ago

Hi @TiesdeKok how are you? Back from vacation? ;-) Do you have time to look that up? Its a great tool but these bugs seriously limit the possible use we can make of ipystata...

Thanks!

TiesdeKok commented 8 years ago

Hi @randomgambit, I am doing great. It is my intention to look into it this weekend or the beginning of next week. The bug with the wrong output will be my priority.

TiesdeKok commented 8 years ago

@randomgambit I have fixed the bug with the margins command output omitting some parts (was related to how I parse out Mata code). However, I am not sure if I can replicate your problem in this issue.

The > #c.price##c.price##c.gear_ratio foreign on the top is something that I can easily fix (a minor issue with the log-file processing. Is this the issue? Or is the issue that you only get

> #c.price##c.price##c.gear_ratio foreign
note: price omitted because of collinearity
note: price omitted because of collinearity
note: gear_ratio omitted because of collinearity

and not the part below (this:)?


      Source |       SS           df       MS      Number of obs   =        74
-------------+----------------------------------   F(11, 62)       =         .
       Model |   635065396        11  57733217.8   Prob > F        =         .
    Residual |           0        62           0   R-squared       =    1.0000
-------------+----------------------------------   Adj R-squared   =    1.0000
       Total |   635065396        73  8699525.97   Root MSE        =         0

------------------------------------------------------------------------------------------
                   price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------------------+----------------------------------------------------------------
                   price |          1          .        .       .            .           .
                         |
         c.price#c.price |  -8.23e-16          .        .       .            .           .
                         |
                   price |          0  (omitted)
                         |
 c.price#c.price#c.price |   3.03e-20          .        .       .            .           .
                         |
              gear_ratio |   5.98e-09          .        .       .            .           .
                  weight |  -5.35e-14          .        .       .            .           .
                headroom |  -3.39e-11          .        .       .            .           .
                     mpg |  -5.70e-12          .        .       .            .           .
                   price |          0  (omitted)
              gear_ratio |          0  (omitted)
                         |
    c.price#c.gear_ratio |  -2.44e-12          .        .       .            .           .
                         |
         c.price#c.price#|
            c.gear_ratio |   2.99e-16          .        .       .            .           .
                         |
 c.price#c.price#c.price#|
            c.gear_ratio |  -1.12e-20          .        .       .            .           .
                         |
                 foreign |  -5.94e-11          .        .       .            .           .
                   _cons |  -1.67e-08          .        .       .            .           .

The reason I ask is because I get the full output when I run your code on my computer. The only thing that is wrong on my computer is the presence of on the > #c.price##c.price##c.gear_ratio foreign line.

randomgambit commented 8 years ago

hi @TiesdeKok thanks for your quick help, no the issue is simply the boring > #c.price##c.price##c.gear_ratio foreign line that appears on the top!

TiesdeKok commented 8 years ago

Ok, I will try to push the fix today. :smile:

TiesdeKok commented 8 years ago

I have pushed a fix (version 0.3.4) to PyPi. If you run: pip install ipystata --ignore-installed both issues should be fixed.

When I find some extra time I will try to implement a feature that allows you to use /// linebreaks.

TiesdeKok commented 8 years ago

I looked into the line break issue given that it was also mentioned in #7.

It actually turned out to be a very easy solution. As long as the /// is directly followed by a new line it should work now with version 0.3.5.

You can update using pip install ipystata --upgrade --force-reinstall

Pleas let me know if you run into any trouble with this solution.

Yuji-Shimohira-Calvo commented 8 years ago

Hi @TiesdeKok. I just found this thread and would like to report that @randomgambit specific problem is solved. However, in other instances I keep getting the "left-overs" of long lines. For instance, if I do:

%%stata -gr
line price weight, lwidth(medthick ..) sort ///
        title(Some graph) subtitle(Something else) ///
        scheme(economist) xtitle(blabla) ytitle(blablabla)

I get the following plus the graph: > ) ytitle(blablabla)

I also get the "left-over" (yet shorter) if I remove the "///" and run the graph on a single line.

I was wondering whether this is due to something I am doing wrong or if it is a more general issue. Thanks for all your effort on this!!

TiesdeKok commented 8 years ago

Thanks for notifying me of this issue, it is entirely possible that I not completely solved the issue.

I will look into it asap.

TiesdeKok commented 7 years ago

Pull request #20 seems to have fixed this problem. Thanks @pacbard!